A view scope represents an isolation within templates. Often times, you have many different areas that have either completely different scoping then others.
Get started by installing it through components:
component install viewjs-scope --save
var scope = require('scope');
Create a new scope through the exported function:
scope(); // new scope.Scope();
Attach a parent to it:
Finally, add attributes:
scope() .set('foo', 123) .set('name', 'John')
.get() method on any scope will, if the key is not found on the immediate scope, bubble up to the parents until it finds it, otherwise it'll return
var parentA = scope().attr('foo', 55); var parentB = scope() .parent(parentA) .attr('world', 'hello'); var child = scope() .parent(parentB) .attr('five', 5);
Now we can grab any one of those attributes by only touching the child scope:
scope.get('five'); // 5 scope.get('world'); // 'hello' scope.get('foo'); // 55
.attr(key, value) is an alias to
Run with mocha
component build --dev
The MIT License (MIT)
Copyright (c) 2014 Daniel Fagnan email@example.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.