Skip to content

Instantly share code, notes, and snippets.

@jongacnik
Last active November 7, 2018 22:19
Show Gist options
  • Save jongacnik/6ed3cea73e128a97361a5800fef6cac5 to your computer and use it in GitHub Desktop.
Save jongacnik/6ed3cea73e128a97361a5800fef6cac5 to your computer and use it in GitHub Desktop.
Choo component cache plugin
var cache
exports.cache = function () {
return cache.apply(this, arguments)
}
exports.plugin = function (state, emitter) {
cache = state.cache
}
@jongacnik
Copy link
Author

Using this in order to avoid passing state all over the place just to create components :)

app.use(require('./choo-cache').plugin)

Elsewhere in the app, perhaps in a view:

var { cache } = require('./plugins/choo-cache')

function view () {
  return html`
    <main>
      ${cache(SomeComponent, 'MyComponent').render()}
    </main>
  `
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment