2017-04-07 07:48:49 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2017-04-07 07:48:49 +00:00
|
|
|
*
|
2018-05-11 02:06:46 +00:00
|
|
|
* @format
|
2018-06-20 07:35:29 +00:00
|
|
|
* @flow strict
|
2017-04-07 07:48:49 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
type Scene = {name: string};
|
|
|
|
|
|
|
|
let _listeners: Array<(scene: Scene) => void> = [];
|
|
|
|
|
|
|
|
let _activeScene = {name: 'default'};
|
|
|
|
|
|
|
|
const SceneTracker = {
|
|
|
|
setActiveScene(scene: Scene) {
|
|
|
|
_activeScene = scene;
|
2018-05-11 02:06:46 +00:00
|
|
|
_listeners.forEach(listener => listener(_activeScene));
|
2017-04-07 07:48:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getActiveScene(): Scene {
|
|
|
|
return _activeScene;
|
|
|
|
},
|
|
|
|
|
2018-05-11 02:06:46 +00:00
|
|
|
addActiveSceneChangedListener(
|
|
|
|
callback: (scene: Scene) => void,
|
|
|
|
): {remove: () => void} {
|
2017-04-07 07:48:49 +00:00
|
|
|
_listeners.push(callback);
|
|
|
|
return {
|
|
|
|
remove: () => {
|
2018-05-11 02:06:46 +00:00
|
|
|
_listeners = _listeners.filter(listener => callback !== listener);
|
2017-04-07 07:48:49 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = SceneTracker;
|