Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- keeping one instance of a dojo module
- require([
- 'some/module'
- ], function (module) {
- module.setSomeValue(3);
- });
- define([
- 'some/module'
- ], function(module) {
- return {
- start: function() {
- var x = module.getSomeValue();
- }
- };
- });
- acompany = window.acompany || {};
- acompany.project = acompany.project || {
- };
- require([
- ], function() {
- var debug = false;
- acompany.project.module = {
- /* static variables and functions here */
- };
- });
- define([
- ], function () {
- return acompany.project.module;
- });
- define([
- 'dojo/_base/lang/',
- 'some/module'
- ], function(lang, module) {
- var m = lang.getObject('some.module', true);
- m.x = 0;
- m.doSomething = function(){
- // doSomething
- };
- return m;
- });
- require([
- 'some/module'
- ], function(someModule) {
- var debug = false;
- /* someModule - static variables and functions here */
- if(someModule.x == 0){
- }
- });
- define("some/module", {
- someValue: "some",
- otherValue: "other"
- });
- require(["some/module"], function(module) {
- console.log("module.someValue", module.someValue); // some
- module.someValue = "some changed";
- });
- require(["some/module"], function(module) {
- console.log("module.someValue", module.someValue); // some changed
- });
- define("some/stateful-module", ["dojo/Stateful"], function(Stateful){
- var stateful = new Stateful({
- someValue: "some",
- otherValue: "other"
- });
- return stateful;
- });
- require(["some/stateful-module"], function(module) {
- console.log("stateful-module.someValue:", module.get("someValue"));
- module.watch(function(name, oldValue, newValue) {
- console.log("stateful-module: property"
- , name
- , "changed from"
- , "'" + oldValue + "'"
- , "to"
- , "'" + newValue + "'"
- );
- });
- });
- require(["some/stateful-module"], function(module) {
- module.set("someValue", "some changed");
- });
Add Comment
Please, Sign In to add comment