Last active
December 13, 2015 21:19
-
-
Save eduardo-matos/4976569 to your computer and use it in GitHub Desktop.
Pausable events on Dojo Toolkit
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
require([ | |
'dojo/on', | |
'MyModule' | |
], function ( | |
on, | |
MyModule | |
) { | |
'use strict'; | |
var mod = new MyModule(); | |
var handler = on.pausable(mod, 'foo', function (fooCount) { | |
console.log('Foo Count: ' + fooCount); | |
}); | |
mod.foo(); // Logs: "Foo Count: 1" | |
handler.pause(); | |
mod.foo(); | |
handler.resume(); | |
mod.foo(); // Logs: "Foo Count: 3" | |
}); |
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
define('MyModule', [ | |
'dojo/_base/declare', | |
'dojo/Evented' | |
], function ( | |
declare, | |
Evented | |
) { | |
var fooCount = 0; | |
return declare([Evented], { | |
foo: function () { | |
fooCount += 1; | |
this.emit('foo', fooCount); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment