Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maxnowack/meteor-reactive-cache
Utilities for caching reactive data in meteor
https://github.com/maxnowack/meteor-reactive-cache
caching meteor react reactivity tracker
Last synced: 3 months ago
JSON representation
Utilities for caching reactive data in meteor
- Host: GitHub
- URL: https://github.com/maxnowack/meteor-reactive-cache
- Owner: maxnowack
- License: mit
- Created: 2017-04-26T10:33:51.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-12T06:20:45.000Z (about 2 years ago)
- Last Synced: 2024-04-14T21:48:51.197Z (9 months ago)
- Topics: caching, meteor, react, reactivity, tracker
- Language: JavaScript
- Size: 360 KB
- Stars: 2
- Watchers: 3
- Forks: 2
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# meteor-reactive-cache [![Build Status](https://travis-ci.org/maxnowack/meteor-reactive-cache.svg?branch=master)](https://travis-ci.org/maxnowack/meteor-reactive-cache)
Utilities for caching reactive data### Installation
````bash
$ npm install --save meteor-reactive-cache
````### Usage
#### `ReactiveCache(compare: function)`
A simple reactive cache. It haves the same API like a `ReactiveDict`, but the values are getting deleted if all wrapped computations are stopped.````es6
import { Tracker } from 'meteor/tracker'
import { ReactiveCache } from 'meteor-reactive-cache'const reactiveCache = new ReactiveCache(/* compareFn */);
reactiveCache.set('foo', 'bar');
const computation = Tracker.autorun(() => {
reactiveCache.get('foo'); // reactive!
})
reactiveCache.set('foo', 'new bar');
computation.stop(); // keys will be invalidated if they don't have reactive dependants
reactiveCache.get('foo'); // undefined
````#### `DataCache(resolve: function, { timeout: number, compare: function })`
Provides a simple reactive data cache, by passing in a function, that resolves a key to data in a reactive context.````es6
import { Tracker } from 'meteor/tracker'
import { DataCache } from 'meteor-reactive-cache'const dataCache = new DataCache((key) => {
// do some expensive reactive work here, which returns the same data for the same key.
// this function will only be executed if a reactive dependency changes or the requested key isn't cached.})
const computation = Tracker.autorun(() => {
reactiveCache.get('foo'); // reactive!
})
computation.stop(); // keys will be invalidated if they don't have reactive dependants
reactiveCache.get('foo'); // undefined
````#### `reactiveField(resolve: function, { timeout: number, compare: function })`
Like DataCache, but with a much simpler API and support for multiple function parameters.````es6
import { Tracker } from 'meteor/tracker'
import { reactiveField } from 'meteor-reactive-cache'const field = reactiveField((val1, val2, val3) => {
// …
})
const computation = Tracker.autorun(() => {
field('foo', 'bar', 1234); // reactive!
})
````## License
Licensed under MIT license. Copyright (c) 2017 Max Nowack## Contributions
Contributions are welcome. Please open issues and/or file Pull Requests.## Maintainers
- Max Nowack ([maxnowack](https://github.com/maxnowack))