Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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