Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tmeasday/meteor-deps-extensions
https://github.com/tmeasday/meteor-deps-extensions
Last synced: 11 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/tmeasday/meteor-deps-extensions
- Owner: tmeasday
- Created: 2012-07-25T03:34:31.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2012-09-16T06:41:37.000Z (over 12 years ago)
- Last Synced: 2024-10-25T18:58:33.254Z (about 2 months ago)
- Language: JavaScript
- Size: 102 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
#Some reactive helpers for meteor
##Install
Use [meteorite](http://oortcloud.github.com/meteorite/):
Then add via:```bash
mrt add deps-extensions
```##Usage
###Adding Reactive Variables
```js
Meteor.deps.add_reactive_variable(object, 'something', default_value)
```Which adds three functions to object: object.something(), object.something.set() and object.something.equals() which behave reactively.
###Using reactive contexts
####`repeat`
```js
Meteor.deps.repeat(fn)
```
Repeatedly call `fn`, once each time the dependencies that it uses changes. For example:
```js
Meteor.deps.repeat(function() {
console.log("current_post_id is: " Session.get('current_post_id'));
});
```####`isolate`
```js
Meteor.deps.isolate(fn)
```
Kill all reactivity inside `fn`, so that the current context isn't ever invalidated by that code. Returns the result of `fn`. For example:
```js
Meteor.deps.isolate(function() {
return Comments.find({}, {order: {score: 1}});
});
```
Will return a list of comments that is 'unreactive' and thus won't reorder as the user reads them.####`await`
```js
Meteor.deps.await(predicate, cb)
```
Repeatedly (reactively) call `predicate` until it's true, then call `cb` *once only*. For example
```js
Meteor.deps.await(function() { return Router.current_page() === 'home'; }, function() {
alert('Welcome to my site! Nice to see you!');
});
```####`memoize`
```js
Meteor.deps.memoize(fn)
```
Returns a function that wraps `fn` in a context, so that `fn`'s reactivity can be maintained, whilst minimizing the number of calls to it. Example:
```js
var cheapReactiveFn = Meteor.deps.memoize(function() {
return expensiveReactiveFn();
});
```
Now `reactiveFn` can be called many times, but `expensiveReactiveFn` will only get called once (per value it returns);