All Projects β†’ jongacnik β†’ component-box

jongacnik / component-box

Licence: MIT License
A little component cacher πŸ“¦

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to component-box

nanoconstruct
Tiny tool to test and develop nanocomponents
Stars: ✭ 12 (-52%)
Mutual labels:  choo, nanocomponent
cacheme-go
πŸš€ Schema based, typed Redis caching/memoize framework for Go
Stars: ✭ 19 (-24%)
Mutual labels:  cache
punic
Punic is a remote cache CLI built for Carthage and Apple .xcframework
Stars: ✭ 25 (+0%)
Mutual labels:  cache
HAProxy-2-RPM-builder
Build latest HAProxy binary with prometheus metrics support
Stars: ✭ 28 (+12%)
Mutual labels:  cache
async-memo-ize
πŸ›  Memoize utility for async/await syntax and promises. It supports cache in memory or via Redis
Stars: ✭ 16 (-36%)
Mutual labels:  cache
type-cacheable
TypeScript-based caching decorator (currently supports Redis, LRU-Cache and NodeCache)
Stars: ✭ 96 (+284%)
Mutual labels:  cache
microstream
High-Performance Java-Native-Persistence. Store and load any Java Object Graph or Subgraphs partially, Relieved of Heavy-weight JPA. Microsecond Response Time. Ultra-High Throughput. Minimum of Latencies. Create Ultra-Fast In-Memory Database Applications & Microservices.
Stars: ✭ 283 (+1032%)
Mutual labels:  cache
composer-install
A GitHub Action to streamline installation of PHP dependencies with Composer.
Stars: ✭ 151 (+504%)
Mutual labels:  cache
Ccache.cmake
πŸš… Compile faster with Ccache! A Ccache integration for CMake with Xcode support.
Stars: ✭ 24 (-4%)
Mutual labels:  cache
AspSqliteCache
An ASP.NET Core IDistributedCache provider backed by SQLite
Stars: ✭ 39 (+56%)
Mutual labels:  cache
lsdis
KV storage based on LocalStorage.
Stars: ✭ 17 (-32%)
Mutual labels:  cache
cachex
CacheXζ³¨θ§£ηΌ“ε­˜ζ‘†ζžΆ
Stars: ✭ 39 (+56%)
Mutual labels:  cache
incache
Powerful key/value in-memory storage or on disk to persist data
Stars: ✭ 16 (-36%)
Mutual labels:  cache
LocalCache
JAVA LocalCache -- JAVA ζœ¬εœ°ηΌ“ε­˜ε·₯ε…·η±»
Stars: ✭ 62 (+148%)
Mutual labels:  cache
GraphCMS-cache-boilerplate
The main goal of this service is to provide a reliable cache contingency backup plan in case a GraphCMS/GraphQL endpoint is failing.
Stars: ✭ 24 (-4%)
Mutual labels:  cache
cache
LRU-based cache package for Go.
Stars: ✭ 25 (+0%)
Mutual labels:  cache
proxpi
PyPI caching mirror
Stars: ✭ 19 (-24%)
Mutual labels:  cache
resilience4clj-circuitbreaker
Resilience4Clj circuit breaker lets you decorate a function call (usually with a potential of external failure) with a safety mechanism to interrupt the propagation of failures.
Stars: ✭ 40 (+60%)
Mutual labels:  cache
salad
Asynchronous Scala Redis Client supporting Sentinel and Redis Cluster
Stars: ✭ 14 (-44%)
Mutual labels:  cache
papercut
Papercut is a scraping/crawling library for Node.js built on top of JSDOM. It provides basic selector features together with features like Page Caching and Geosearch.
Stars: ✭ 15 (-40%)
Mutual labels:  cache

component-box πŸ“¦


A little component cacher for things like nanocomponent

Usage

var Nanocomponent = require('nanocomponent')
var html = require('bel')
var c = require('component-box')

// component
class MyComponent extends Nanocomponent {
  createElement (text) {
    return html`<div>${text}</div>`
  }
}

// function which returns component instance
function createMyComponent () {
  return new MyComponent()
}

c.use({
  mycomponent: createMyComponent
})

// return and render new `mycomponent`
c('mycomponent').render()

Meanwhile in another file...

var c = require('component-box')

// return and render cached `mycomponent`
c('mycomponent').render()

API

component = c(name, key)

Return a component. key is optional. Works as follows:

// return new `mycomponent` and cache as `mycomponent`
c('mycomponent')

// return cached `mycomponent`
c('mycomponent')

// return new `mycomponent` and cache as `boop`
c('mycomponent', 'boop')

// return cached `mycomponent` with key `boop`
c('mycomponent', 'boop')

// always return new `mycomponent` (never cache)
c('mycomponent', false)

c.use([components])

Add components to the store. Object values expect Functions which return a component.

var c = require('component-box')

c.use({
  beep: beepComponent,
  boop: boopComponent
})

c('beep').render()
c('boop').render()

These are shared throughout your app, so in another file you don't need to re-.use:

var c = require('component-box')

c('beep').render()
c('boop').render()

c.delete(key)

Remove component from the cache

// return new `mycomponent` and cache as `mycomponent`
c('mycomponent')

// remove `mycomponent` from cache
c.delete('mycomponent')

// return new `mycomponent` and cache as `mycomponent`
c('mycomponent')

c.cache(cache)

Use a custom cache implementation. Expects an object with .get, .set, and .remove methods.

var c = require('component-box')

c.cache(require('lru')(2)) // only cache 2 instances, using lru eviction

c.use({
  post: postComponent
})

c('post', 'slug1').render()
c('post', 'slug2').render()
c('post', 'slug3').render() // evict 'post-slug1' and return new 'post-slug3' instance

Alternative Pattern

You could also choose to only return the .render method from nanocomponent, allowing for a slightly more concise syntax:

// function which creates component instance and returns render method
function createMyComponent () {
  var component = new MyComponent()
  return function () {
    return component.render(...arguments)
  }
}
// directly calls nanocomponent .render
c('mycomponent')()

Real World

This module is useful when you are creating components on the fly. References to components are saved for you based on keys, that way on app re-renders it will re-use your components so things like load and etc are not wonky.

In this example we are using post slugs as component keys:

var html = require('bel')
var c = require('component-box')

c.use({
  post: require('my-post-component')
})

var postsData = [
  { title: 'Beep', slug: 'beep' },
  { title: 'Boop', slug: 'boop' },
  { title: 'Blap', slug: 'blap' }
]

function view () {
  var posts = postsData.map(function (post) {
    return c('post', post.slug).render(post)
  })

  return html`<div>${posts}</div>`
}

More Examples

fun-component

var component = require('fun-component')
var html = require('bel')
var c = require('component-box')

// function which returns a component
function mycomponent () {
  return component(function (props) {
    return html`<div>Hello!<div>`
  })
}

c.use({
  mycomponent: mycomponent
})

// return new `mycomponent`
c('mycomponent')()

See Also

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].