Skip to content

Instantly share code, notes, and snippets.

@odoe
Created June 1, 2015 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odoe/df4961f7eed6921369b8 to your computer and use it in GitHub Desktop.
Save odoe/df4961f7eed6921369b8 to your computer and use it in GitHub Desktop.
// 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