public
Description: MVC Style Controller extension for MooTools. Data binding is your friend!
Homepage:
Clone URL: git://github.com/subtleGradient/mootools-mvc-controller.git
WIP - READ ME!
Thomas Aylott (author)
Fri Dec 26 09:04:51 -0800 2008
commit  ac23514e7d1ba7d89356be1eced19b693ab38f71
tree    42747c9095cce6f4ff113ce29974f263df818f3f
parent  956a02e1b866bbca88044e88e1ed3fa39fb70afd
...
1
2
 
3
4
5
6
 
 
7
8
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
11
12
...
 
 
1
2
 
 
 
3
4
5
 
 
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
 
 
0
@@ -1,12 +1,74 @@
0
-My Plugin Name
0
-==============
0
+***Still a work in progress, not released yet***
0
 
0
-Description
0
------------
0
-Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
0
+SubtleController
0
+================
0
 
0
-Getting Started
0
----------------
0
+What's it for?
0
+--------------
0
+Data binding! Keep many objects up-to-date without any of your objects knowing about eachother.
0
+
0
+
0
+How it works
0
+------------
0
+
0
+### Setup
0
+1. Create some objects that implement the controller client api
0
+  
0
+  * Read/Write objects must implement get, set, Events & the 'change' event
0
+
0
+      readWriteObject1 = {
0
+        get: function(){},
0
+        set: function(){},
0
+        addEvent: function(type){}
0
+      }
0
+      readWriteObject2 = {
0
+        get: function(){},
0
+        set: function(){},
0
+        addEvent: function(type){}
0
+      }
0
+  
0
+
0
+  * Read only objects have to implement set with both a key and value argument
0
+
0
+      readOnlyObject1 = { set: function(key,value){} }
0
+      readOnlyObject2 = { set: function(key,value){} }
0
+
0
+  * Custom functions only have to support a single argument
0
+
0
+      customFunction1 = function(value){};
0
+      customFunction2 = function(value){};
0
+
0
+2. Create a controller
0
+
0
+    var myController = new SubtleController();
0
+
0
+3. Bind your objects to the controller
0
+
0
+    myController.addBinding(readWriteObject1, 'controllerKey', 'readWriteObject1Key');
0
+    myController.addBinding(readWriteObject2, 'controllerKey', 'readWriteObject2Key');
0
+    myController.addBinding(readOnlyObject1, 'controllerKey', 'readOnlyObject1Key');
0
+    myController.addBinding(readOnlyObject2, 'controllerKey', 'readOnlyObject2Key');
0
+    myController.addBinding(customFunction1, 'controllerKey');
0
+    myController.addBinding(customFunction2, 'controllerKey');
0
+
0
+### Automatic Updates
0
+1. Modify one of your read/write objects
0
+
0
+    readWriteObject1.set('readWriteObject1Key', 'some random value');
0
+
0
+2. Commit your changes by firing the change event  
0
+*optionally, you may pass a string, or array of strings, for the keys that have changed*
0
+
0
+    readWriteObject1.fireEvent('change', 'readWriteObject1Key');
0
+  
0
+3. The Controller updates itself with the updated values. **It does this itself**
0
+
0
+    myController.set('controllerKey', readWriteObject1.get('viewKey'));
0
+
0
+4. The Controller updates all the bindings. **It does this itself**
0
+
0
+    readWriteObject1.set('readWriteObject1Key', myController.get('controllerKey'));
0
+    readWriteObject2.set('readWriteObject2Key', myController.get('controllerKey'));
0
+    readOnlyObject1.set('readOnlyObject1Key', myController.get('controllerKey'));
0
+    readOnlyObject2.set('readOnlyObject2Key', myController.get('controllerKey'));
0
 
0
-1. First, rename the SubtleController.js files to whatever the name of your plugin is
0
-2. Replace every occurrence of "SubtleController" with your plugins actual name
...
19
20
21
22
 
23
24
25
26
 
 
 
 
 
 
 
27
28
29
...
198
199
200
 
 
 
 
...
19
20
21
 
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
...
205
206
207
208
209
210
211
0
@@ -19,11 +19,18 @@ var SubtleController = new Class({
0
   
0
   initialize: function(data, options){
0
     this.setOptions(options);
0
-    this.bindings = $H(data);
0
+    this.bindings = [$H(data)];
0
     window.addEvent('domready',function(){ this.ready = true; }.bind(this));
0
     return this.fireEvent('initialize');
0
   },
0
   
0
+  get: function(key){
0
+    return this.bindings[0].get(key);
0
+  },
0
+  set: function(key, value){
0
+    return this.updateOne(key, value);
0
+  },
0
+  
0
   update: function(keys){
0
     try{console.log( "  update("+keys+")" );}catch(e){};
0
     keys = $splat(keys);
0
@@ -198,3 +205,7 @@ SubtleController.Defaults = new Class({
0
 //     NSWindowController
0
 //     NSDocumentController
0
 // 
0
+
0
+
0
+
0
+
...
1
2
3
4
 
 
 
5
6
7
...
20
21
22
23
 
 
 
 
 
24
25
26
...
1
2
3
 
4
5
6
7
8
9
...
22
23
24
 
25
26
27
28
29
30
31
32
0
@@ -1,7 +1,9 @@
0
 describe('SubtleController', {
0
 
0
   'before all': function(){
0
-    controller = new SubtleController();
0
+    controller = new SubtleController({
0
+      'key':'value'
0
+    });
0
   },
0
 
0
   'after all': function(){
0
@@ -20,7 +22,11 @@ describe('SubtleController', {
0
   'should implement addBinding': function(){
0
     value_of(typeof controller.addBinding).should_be('function');
0
   },
0
-
0
+  
0
+  'should get value': function(){
0
+    value_of(controller.get('key')).should_be('value');
0
+  },
0
+  
0
   '':$empty
0
 });
0
 

Comments