Guest User

Untitled

a guest
Jan 13th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. keeping one instance of a dojo module
  2. require([
  3. 'some/module'
  4. ], function (module) {
  5. module.setSomeValue(3);
  6. });
  7.  
  8. define([
  9. 'some/module'
  10. ], function(module) {
  11. return {
  12. start: function() {
  13. var x = module.getSomeValue();
  14. }
  15. };
  16. });
  17.  
  18. acompany = window.acompany || {};
  19. acompany.project = acompany.project || {
  20. };
  21.  
  22. require([
  23. ], function() {
  24. var debug = false;
  25.  
  26. acompany.project.module = {
  27. /* static variables and functions here */
  28. };
  29. });
  30.  
  31. define([
  32.  
  33. ], function () {
  34. return acompany.project.module;
  35. });
  36.  
  37. define([
  38. 'dojo/_base/lang/',
  39. 'some/module'
  40. ], function(lang, module) {
  41.  
  42. var m = lang.getObject('some.module', true);
  43. m.x = 0;
  44. m.doSomething = function(){
  45. // doSomething
  46. };
  47. return m;
  48. });
  49.  
  50. require([
  51. 'some/module'
  52. ], function(someModule) {
  53. var debug = false;
  54.  
  55. /* someModule - static variables and functions here */
  56.  
  57. if(someModule.x == 0){
  58.  
  59. }
  60. });
  61.  
  62. define("some/module", {
  63. someValue: "some",
  64. otherValue: "other"
  65. });
  66.  
  67. require(["some/module"], function(module) {
  68. console.log("module.someValue", module.someValue); // some
  69. module.someValue = "some changed";
  70. });
  71.  
  72. require(["some/module"], function(module) {
  73. console.log("module.someValue", module.someValue); // some changed
  74. });
  75.  
  76. define("some/stateful-module", ["dojo/Stateful"], function(Stateful){
  77. var stateful = new Stateful({
  78. someValue: "some",
  79. otherValue: "other"
  80. });
  81. return stateful;
  82. });
  83.  
  84. require(["some/stateful-module"], function(module) {
  85. console.log("stateful-module.someValue:", module.get("someValue"));
  86. module.watch(function(name, oldValue, newValue) {
  87. console.log("stateful-module: property"
  88. , name
  89. , "changed from"
  90. , "'" + oldValue + "'"
  91. , "to"
  92. , "'" + newValue + "'"
  93. );
  94. });
  95. });
  96.  
  97. require(["some/stateful-module"], function(module) {
  98. module.set("someValue", "some changed");
  99. });​
Add Comment
Please, Sign In to add comment