https://github.com/cotag/scope-buster
AngularJS tool for sharing variables across different scopes
https://github.com/cotag/scope-buster
Last synced: 3 days ago
JSON representation
AngularJS tool for sharing variables across different scopes
- Host: GitHub
- URL: https://github.com/cotag/scope-buster
- Owner: cotag
- Created: 2014-07-24T01:34:42.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2014-07-29T14:01:45.000Z (almost 12 years ago)
- Last Synced: 2026-05-30T00:18:57.321Z (27 days ago)
- Language: JavaScript
- Size: 148 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Scope Buster
Scope buster is used to connect data from various scopes without leakage.
For instance, linking a search box in the header to a controller for the view whilst also maintaining a search parameter in the URL and providing either rate limiting or debouncing at the same time.
1. Open your bower.json
2. Add `"scope-buster": "~1.0.0"` to your dependency list
3. Run `bower install`
4. In your application you can now add:
* ``
* Add `scopeBuster` to your module list in your app
## AngularJS Usage
```js
scopeBuster.pub(otherScope, 'variable.name', {
// Optional options
mapping: 'name.of.scopeBuster.variable', // defaults to variable.name provided
persist: false, // Hold value after scope has been destroyed
routeParam: 'query', // name of the routeParam that should be kept in sync
// Both these default to false
// debounce: 200, // ms without change before we apply the value after an update
// ratelimit: 200 // ms before we apply the latest value
});
// Then in another scope you can:
scopeBuster.sub(scope, 'local', 'name.of.scopeBuster.variable');
// Then you can watch for changes or bind to the variable
// i.e.
scope.$watch('local', function (newVar) {
// newVar === otherScope.variable.name
});
```
It is up to you to ensure variables are namespaced correctly in scopeBuster so that there are no clashes.