mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Issue #277 : Switch HeaderController to events instead of infinite setTimeout
This commit is contained in:
parent
669d7a21cb
commit
b859857b2d
@ -36,6 +36,8 @@ var Events = {
|
||||
*/
|
||||
PISKEL_RESET: 'PISKEL_RESET',
|
||||
PISKEL_SAVE_STATE: 'PISKEL_SAVE_STATE',
|
||||
PISKEL_DESCRIPTOR_UPDATED : 'PISKEL_DESCRIPTOR_UPDATED',
|
||||
PISKEL_SAVED_STATUS_UPDATE : 'PISKEL_SAVED_STATUS_UPDATE',
|
||||
|
||||
HISTORY_STATE_SAVED: 'HISTORY_STATE_SAVED',
|
||||
HISTORY_STATE_LOADED: 'HISTORY_STATE_LOADED',
|
||||
|
@ -5,12 +5,9 @@
|
||||
* When embedded in piskelapp.com, the page adds a header containing the name of the currently edited sprite
|
||||
* This controller will keep the displayed name in sync with the actual piskel name
|
||||
*/
|
||||
ns.HeaderController = function (piskelController, savedStatusService, interval) {
|
||||
ns.HeaderController = function (piskelController, savedStatusService) {
|
||||
this.piskelController = piskelController;
|
||||
this.savedStatusService = savedStatusService;
|
||||
this.interval = interval || 500;
|
||||
|
||||
this.updateHeader_ = this.updateHeader_.bind(this);
|
||||
};
|
||||
|
||||
ns.HeaderController.prototype.init = function () {
|
||||
@ -19,6 +16,10 @@
|
||||
$.subscribe(Events.BEFORE_SAVING_PISKEL, this.onBeforeSavingPiskelEvent_.bind(this));
|
||||
$.subscribe(Events.AFTER_SAVING_PISKEL, this.onAfterSavingPiskelEvent_.bind(this));
|
||||
|
||||
$.subscribe(Events.PISKEL_DESCRIPTOR_UPDATED, this.updateHeader_.bind(this));
|
||||
$.subscribe(Events.PISKEL_RESET, this.updateHeader_.bind(this));
|
||||
$.subscribe(Events.PISKEL_SAVED_STATUS_UPDATE, this.updateHeader_.bind(this));
|
||||
|
||||
this.updateHeader_();
|
||||
};
|
||||
|
||||
@ -35,8 +36,6 @@
|
||||
} catch (e) {
|
||||
console.warn('Could not update header : ' + e.message);
|
||||
}
|
||||
|
||||
window.setTimeout(this.updateHeader_, this.interval);
|
||||
};
|
||||
|
||||
ns.HeaderController.prototype.onBeforeSavingPiskelEvent_ = function () {
|
||||
|
@ -114,10 +114,12 @@
|
||||
|
||||
ns.Piskel.prototype.setDescriptor = function (descriptor) {
|
||||
this.descriptor = descriptor;
|
||||
$.publish(Events.PISKEL_DESCRIPTOR_UPDATED);
|
||||
};
|
||||
|
||||
ns.Piskel.prototype.setName = function (name) {
|
||||
this.descriptor.name = name;
|
||||
$.publish(Events.PISKEL_DESCRIPTOR_UPDATED);
|
||||
};
|
||||
|
||||
ns.Piskel.prototype.getHash = function () {
|
||||
|
@ -32,7 +32,10 @@
|
||||
|
||||
ns.SavedStatusService.prototype.updateDirtyStatus = function (status) {
|
||||
var piskel = this.piskelController.getPiskel();
|
||||
piskel.isDirty_ = status;
|
||||
if (piskel.isDirty_ != status) {
|
||||
piskel.isDirty_ = status;
|
||||
$.publish(Events.PISKEL_SAVED_STATUS_UPDATE);
|
||||
}
|
||||
};
|
||||
|
||||
ns.SavedStatusService.prototype.isDirty = function (evt) {
|
||||
|
Loading…
Reference in New Issue
Block a user