瀏覽代碼

start return model wrapper; AppVM global in demo.

Herbert Vojčík 11 年之前
父節點
當前提交
b6bf0e8d2f
共有 8 個文件被更改,包括 32 次插入48 次删除
  1. 13 7
      README.md
  2. 2 1
      demo.html
  3. 0 11
      js/Trapped-Demo.deploy.js
  4. 0 16
      js/Trapped-Demo.js
  5. 7 2
      js/Trapped-Frontend.deploy.js
  6. 9 4
      js/Trapped-Frontend.js
  7. 0 6
      st/Trapped-Demo.st
  8. 1 1
      st/Trapped-Frontend.st

+ 13 - 7
README.md

@@ -30,12 +30,14 @@ Then start the server: `node vendor/amber/server/server.js`. It start on port 40
 Visit `http://localhost:4000/demo.html` in your browser. Amber IDE opens.
 
 Trapped itself is in `Trapped-Frontend` and `Trapped-Backend` packages.
-Rhe demo page itself is in `demo.html` and its code is in `Trapped-Demo` package,
+The demo page itself is in `demo.html` and its code is in `Trapped-Demo` package,
 in classes `App` and `AppView`.
 Other classes in `Trapped-Demo` are just prototype implemenations of Trapped
 building blocks. They may be deleted in the future or move to frontend/backend packages
 when they mature.
 Anyway, the code of the page is in `App` (the view model) and `AppView` (the view).
+The `App` instance is put into global `AppVM` variable in `demo.html` initialization.
+
 Trapped is pretty light: the view model wraps any object (via `payload:`,
 as seen in `App >> initialize`). The view is subclass of plain `Widget`, but inside it,
 uses of `trapShow:` (which itself uses `trap:read:`) and `trapDescend:` allows you
@@ -44,17 +46,21 @@ to bind data from view model.
 To see viewmodel->view update working, try
 
 ```smalltalk
-| app |
-app := Trapped current byName: 'App'. "to get to the App instance. Normally you remember it yourself."
-app modify: #('items') do: [ :old | old, { '!' } ] "use modify:do: to change viewmodel"
+AppVM modify: #('items') do: [ :old | old, { '!' } ]
 ```
 
 The number and list of items should update. If you do
 
 ```smalltalk
-| app |
-app := Trapped current byName: 'App'. "to get to the App instance. Normally you remember it yourself."
-app modify: #('title') do: [ :old | 'My title' ] "use modify:do: to change viewmodel"
+AppVM modify: #('title') do: [ :old | 'My title' ]
 ```
 
 The title of the page as well as header should be updated.
+
+The `modify:do:` should be used for update since it changes as well as signals the change.
+It is planned that `read:do:` and `modify:do:` will guard the data by doing deep copies
+behind the scene against remembering and modifying out of sync.
+If you wish to, you can change the raw data you put into `payload:` by hand,
+but then be sure to call `AppVM changed: #('title')` or similar
+(you can do `AppVM changed: #()` to signal everything in `AppVM` has changed,
+but then everything depending upon it will redraw).

+ 2 - 1
demo.html

@@ -5,13 +5,14 @@
 </head>
 <body>
 <script type="text/javascript">
+    var AppVM;
     loadAmber({
         packages:['Trapped-Backend', 'Trapped-Frontend', 'Trapped-Demo'],
         packageHome:'./',
         ready:function () {
             $(function() {
                 smalltalk.Browser._openOn_(smalltalk.App);
-                smalltalk.App._start();
+                AppVM = smalltalk.App._start();
                 smalltalk.Trapped._start();
             });
         }

+ 0 - 11
js/Trapped-Demo.deploy.js

@@ -101,17 +101,6 @@ return self}
 smalltalk.TrappedPlainModel);
 
 
-smalltalk.addMethod(
-"_start",
-smalltalk.method({
-selector: "start",
-fn: function (){
-var self=this;
-smalltalk.send(smalltalk.send(self,"_new",[]),"_start",[]);
-return self}
-}),
-smalltalk.TrappedPlainModel.klass);
-
 
 smalltalk.addClass('App', smalltalk.TrappedPlainModel, [], 'Trapped-Demo');
 smalltalk.addMethod(

+ 0 - 16
js/Trapped-Demo.js

@@ -136,22 +136,6 @@ referencedClasses: []
 smalltalk.TrappedPlainModel);
 
 
-smalltalk.addMethod(
-"_start",
-smalltalk.method({
-selector: "start",
-category: 'action',
-fn: function (){
-var self=this;
-smalltalk.send(smalltalk.send(self,"_new",[]),"_start",[]);
-return self},
-args: [],
-source: "start\x0a\x09self new start",
-messageSends: ["start", "new"],
-referencedClasses: []
-}),
-smalltalk.TrappedPlainModel.klass);
-
 
 smalltalk.addClass('App', smalltalk.TrappedPlainModel, [], 'Trapped-Demo');
 smalltalk.addMethod(

+ 7 - 2
js/Trapped-Frontend.deploy.js

@@ -103,8 +103,13 @@ smalltalk.method({
 selector: "start",
 fn: function (){
 var self=this;
-smalltalk.send(smalltalk.send(self,"_new",[]),"_start",[]);
-return self}
+var $2,$3,$1;
+$2=smalltalk.send(self,"_new",[]);
+smalltalk.send($2,"_start",[]);
+$3=smalltalk.send($2,"_yourself",[]);
+$1=$3;
+return $1;
+}
 }),
 smalltalk.TrappedModelWrapper.klass);
 

+ 9 - 4
js/Trapped-Frontend.js

@@ -146,11 +146,16 @@ selector: "start",
 category: 'action',
 fn: function (){
 var self=this;
-smalltalk.send(smalltalk.send(self,"_new",[]),"_start",[]);
-return self},
+var $2,$3,$1;
+$2=smalltalk.send(self,"_new",[]);
+smalltalk.send($2,"_start",[]);
+$3=smalltalk.send($2,"_yourself",[]);
+$1=$3;
+return $1;
+},
 args: [],
-source: "start\x0a\x09self new start",
-messageSends: ["start", "new"],
+source: "start\x0a\x09^self new start; yourself",
+messageSends: ["start", "new", "yourself"],
 referencedClasses: []
 }),
 smalltalk.TrappedModelWrapper.klass);

+ 0 - 6
st/Trapped-Demo.st

@@ -60,12 +60,6 @@ initialize
     self dispatcher: TrappedDumbDispatcher new
 ! !
 
-!TrappedPlainModel class methodsFor: 'action'!
-
-start
-	self new start
-! !
-
 TrappedPlainModel subclass: #App
 	instanceVariableNames: ''
 	package: 'Trapped-Demo'!

+ 1 - 1
st/Trapped-Frontend.st

@@ -63,7 +63,7 @@ watch: path do: aBlock
 !TrappedModelWrapper class methodsFor: 'action'!
 
 start
-	self new start
+	^self new start; yourself
 ! !
 
 Object subclass: #TrappedSingleton