-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
All PIXI.Applications are initiated on the PIXI shared ticker, allowing them to all be controlled simultaneously. PIXI.Ticker.shared is controlled via TimeGraphRenderController and RenderEvents. RenderEvents fires custom events that are handled by event handlers initiated in the RenderController. RenderController is created in the UnitController; this is only because we need one RenderController and there is already only one UnitController. RenderEvents currently fires start-render events in: - TimeGraphComponent on creation and update. - StateController when scrolling up/down Stop render is debounced at a 1000ms after start render. Fixes #7 Signed-off-by: Will Yang <william.yang@ericsson.com>
- Loading branch information
1 parent
a4abe84
commit 7cd081b
Showing
5 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { throttle, debounce } from 'lodash'; | ||
import * as PIXI from 'pixi.js-legacy'; | ||
|
||
const START_RENDER_STRING = 'startPixiRender'; | ||
const STOP_RENDER_STRING = 'stopPixiRender'; | ||
|
||
const throttledStart = throttle(() => { | ||
window.dispatchEvent(new Event(START_RENDER_STRING)); | ||
}, 450, { leading: true }); | ||
|
||
const debouncedStop = debounce(() => { | ||
window.dispatchEvent(new Event(STOP_RENDER_STRING)); | ||
}, 1000); | ||
|
||
interface RenderEvents { | ||
startRender: () => void; | ||
stopRender: () => void; | ||
}; | ||
|
||
export const RenderEvents: RenderEvents = { | ||
/** | ||
* Fires an event that will start the PIXI.Ticker. | ||
* This will start rendering. | ||
* Event handler located in time-graph-render-controller.ts | ||
*/ | ||
startRender: () => { | ||
throttledStart(); | ||
}, | ||
/** | ||
* Fires an event that will stop the PIXI.Ticker. | ||
* This will stop rendering. | ||
* Event handler located in time-graph-render-controller.ts | ||
*/ | ||
stopRender: () => { | ||
debouncedStop(); | ||
} | ||
}; | ||
export class TimeGraphRenderController { | ||
constructor() { | ||
this.initializeRenderEvents(); | ||
} | ||
|
||
private initializeRenderEvents = () => { | ||
|
||
const { startRender, stopRender } = this; | ||
|
||
window.addEventListener(START_RENDER_STRING, startRender); | ||
window.addEventListener(STOP_RENDER_STRING, stopRender); | ||
|
||
window.addEventListener('beforeunload', () => { | ||
window.removeEventListener(START_RENDER_STRING, startRender); | ||
window.removeEventListener(STOP_RENDER_STRING, stopRender); | ||
}); | ||
|
||
}; | ||
|
||
public startRender = () => { | ||
PIXI.Ticker.shared.start(); | ||
debouncedStop(); | ||
}; | ||
|
||
public stopRender = () => { | ||
PIXI.Ticker.shared.stop(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters