|
49 | 49 | Just write javascript. Really; write _any_ javascript inline with your markup and it just works (tm).
|
50 | 50 |
|
51 | 51 | Known exceptions to 'just working':
|
52 |
| -`var` statements do bad things (like write tags), since they try to bind to the context. As a workaround (until I start |
53 |
| -using the new Proxy API - _and_ `node` supports the new Proxy API), store all scratch variables on $scope (if you're |
54 |
| -using an explicit context, you can pass a different identifier as the first argument to the context-generator, |
55 |
| -if $scope is too long/misleading for you). |
| 52 | +`var` statements don't function immediately within an explicitly defined context. |
| 53 | +Make an IIFE within the explicit with (like in the first test) to get around the problem, |
| 54 | +or use implied contexts. Or don't use locals. |
56 | 55 |
|
57 | 56 | Scope
|
58 | 57 | -------
|
@@ -109,7 +108,7 @@ module.exports = function() {
|
109 | 108 | });
|
110 | 109 | };
|
111 | 110 | ```
|
112 |
| -Since `http` (and `sink`, and `JSON`) will be overridden by the implicit context. You have two options: |
| 111 | +Since `http` (and `JSON`) will be overridden by the implicit context. You have two options: |
113 | 112 | - Export the desired functions into the `$scope`
|
114 | 113 | - Utilize _explicit contexts_ for complicated files
|
115 | 114 |
|
@@ -173,36 +172,36 @@ Scope object passed in the options object:
|
173 | 172 | `not.js` File:
|
174 | 173 | ```js
|
175 | 174 | module.exports = function() {
|
176 |
| - $scope.promise = new $scope.Promise(function(resolve, reject) { |
177 |
| - $scope.http.get('www.github.com', function(cli) { |
178 |
| - $scope.sink = ''; |
| 175 | + var promise = new $scope.Promise(function(resolve, reject) { |
| 176 | + $scope.http.get('http://www.github.com', function(cli) { |
| 177 | + var sink = ''; |
179 | 178 | cli.on('data', function(data) {
|
180 |
| - $scope.sink += data; |
| 179 | + sink += data; |
181 | 180 | });
|
182 | 181 | cli.on('end', function() {
|
183 | 182 | $(sink, true);
|
184 | 183 | resolve(); //The return value of implied functions isn't actually used
|
185 | 184 | });
|
186 | 185 | cli.on('error', function(e) {
|
187 |
| - $scope.error = $scope.JSON.parse(e); |
| 186 | + var error = $scope.JSON.parse(e); |
188 | 187 | html
|
189 | 188 | head
|
190 |
| - meta({title: $scope.error}) |
| 189 | + meta({title: error}) |
191 | 190 | $head
|
192 | 191 | body
|
193 |
| - $($scope.error); |
| 192 | + $(error); |
194 | 193 | $body
|
195 | 194 | $html
|
196 | 195 | resolve();
|
197 | 196 | });
|
198 | 197 | });
|
199 | 198 | });
|
200 | 199 |
|
201 |
| - return $scope.promise //Implied functions that return promises have their .proxy attribute |
202 |
| - //set to the proxy generated for them - call .collect() on the proxy |
203 |
| - //to get the result string when the promise resolves |
204 |
| - //eg. promise.then(function() { return promise.proxy.collect(); }) |
205 |
| - // .then(function(rendered) {doStuff(rendered);}); |
| 200 | + return promise; //Implied functions that return promises have their .proxy attribute |
| 201 | + //set to the proxy generated for them - call .collect() on the proxy |
| 202 | + //to get the result string when the promise resolves |
| 203 | + //eg. promise.then(function() { return promise.proxy.collect(); }) |
| 204 | + // .then(function(rendered) {doStuff(rendered);}); |
206 | 205 | };
|
207 | 206 | ```
|
208 | 207 |
|
|
219 | 218 | ====
|
220 | 219 | Doctype shorthand?
|
221 | 220 | Shorthand for inlining a script (something shorter than `script({type: 'text/javascript'}); $($scope.func.toString(), true); script`)
|
222 |
| -Figure out how to fix 'var' within the dsl sensibly. Likely involves some metatrickery with the correct flow of calls through the proxy object chain (just overriding `get` hasn't worked, in my experience). It's complicated by variable hoisting. |
223 | 221 | Benchmarks?
|
0 commit comments