Move ReviveEditor and ReviveHistory to App

This commit is contained in:
Eric NGUYEN 2022-10-13 11:56:41 +02:00
parent 8962132a4d
commit fb6bc1289d
3 changed files with 55 additions and 53 deletions

View file

@ -152,6 +152,32 @@
const component = this.GetAppComponent();
component.dispatchEvent(new CustomEvent(eventType, { detail: isLoaded }))
}
/**
* Revive the references in the editor state by mutation
* Useful after using JSON.stringify with a replacer
* @param editorState Editor state to revive
* @param callback Callback with the revived state
*/
public ReviveEditorState(editorState: IEditorState, callback: (state: IEditorState) => void) {
const eventType = 'reviveEditorState';
this.app.AddEventListener(eventType, callback);
const component = this.GetAppComponent();
component.dispatchEvent(new CustomEvent(eventType, { detail: editorState }));
}
/**
* Revive the references in the history by mutation
* Useful after using JSON.stringify with a replacer
* @param history History to revive
* @param callback Callback with the revived state
*/
public ReviveHistory(history: IHistoryState[], callback: (state: IHistoryState[]) => void) {
const eventType = 'reviveHistory';
this.app.AddEventListener(eventType, callback);
const component = this.GetAppComponent();
component.dispatchEvent(new CustomEvent(eventType, { detail: history }));
}
}
@ -206,7 +232,7 @@
/**
* Return in a callback the current history of the editor as string
* @param callback
* @param callback
*/
public GetEditorStateAsString(callback: (state: string) => void) {
const eventType = 'getEditorStateAsString';
@ -227,32 +253,6 @@
component.dispatchEvent(new CustomEvent(eventType, { detail: history }));
}
/**
* Revive the references in the editor state by mutation
* Useful after using JSON.stringify with a replacer
* @param editorState Editor state to revive
* @param callback Callback with the revived state
*/
public ReviveEditorState(editorState: IEditorState, callback: (state: IEditorState) => void) {
const eventType = 'reviveEditorState';
this.app.AddEventListener(eventType, callback);
const component = this.GetEditorComponent();
component.dispatchEvent(new CustomEvent(eventType, { detail: editorState }));
}
/**
* Revive the references in the history by mutation
* Useful after using JSON.stringify with a replacer
* @param history History to revive
* @param callback Callback with the revived state
*/
public ReviveHistory(history: IHistoryState[], callback: (state: IHistoryState[]) => void) {
const eventType = 'reviveHistory';
this.app.AddEventListener(eventType, callback);
const component = this.GetEditorComponent();
component.dispatchEvent(new CustomEvent(eventType, { detail: history }));
}
/**
* Add a new state to the editor
* @param historyState New history state to append