https://github.com/jongacnik/choo-shortcache
shortcut access to state.cache anywhere in your app
https://github.com/jongacnik/choo-shortcache
Last synced: about 1 year ago
JSON representation
shortcut access to state.cache anywhere in your app
- Host: GitHub
- URL: https://github.com/jongacnik/choo-shortcache
- Owner: jongacnik
- Created: 2018-11-13T19:38:19.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-13T19:45:42.000Z (over 7 years ago)
- Last Synced: 2025-02-28T09:21:06.690Z (over 1 year ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# choo-shortcache
shortcut access to `state.cache()` anywhere in your app
## Example
```js
app.use(require('choo-shortcache'))
```
Elsewhere in your app...
```js
var { cache } = require('choo-shortcache')
var MyComponent = require('./mycomponent')
module.exports = function (state, emit) {
return html`
${cache(MyComponent, 'MyComponent').render()}
`
}
```
## What is this for?
(nano)component instances are managed in `choo` using `state.cache()`. This pattern works well, but it requires you pass `state` everywhere, potentially very deep into your app, just to create components. This plugin allows you to create components at any depth level in your app without directly passing the entire state all the way down. Under the hood it just creates a reference to `state.cache()` that you can import with:
```js
var { cache } = require('choo-shortcache')
```