Created
June 1, 2015 16:32
-
-
Save odoe/df4961f7eed6921369b8 to your computer and use it in GitHub Desktop.
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 AMD syntax | |
define([ | |
'dojo/_base/declare', | |
'dojo/Stateful', | |
'dojo/topic' | |
], function( | |
declare, Stateful, topic | |
) { | |
var Store = declare([Stateful], { | |
x: 0, | |
y: 0 | |
}); | |
// http://www.anujgakhar.com/2013/08/29/singletons-in-dojo/ | |
if (!_instance) { | |
var _instance = new Store(); | |
topic.subscribe('UPDATE-XY', function(data) { | |
_instance.set('x', data.x); | |
_instance.set('y', data.y); | |
}); | |
} | |
return _instance; | |
}); | |
// ES6 syntax | |
import Stateful from 'dojo/Stateful'; | |
import topic from 'dojo/topic'; | |
class Store extends Stateful { | |
constructor() { | |
super(); | |
this.set('x', 0); | |
this.set('y', 0); | |
} | |
}; | |
// http://www.anujgakhar.com/2013/08/29/singletons-in-dojo/ | |
if (!_instance) { | |
var _instance = new Store(); | |
topic.subscribe('UPDATE-XY', (data) => { | |
_instance.set('x', data.x); | |
_instance.set('y', data.y); | |
}); | |
} | |
export default _instance; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment