0.4.0 • Published 7 months ago

lasset v0.4.0

Weekly downloads
-
License
ISC
Repository
-
Last release
7 months ago

Lasset

Lasset exists because cache invalidation is hard especially when cache entries are interdependent.

Usage

import {Lasset} from 'lasset'

// Create lasset that supports two asset factories brick and wall
const assets = new Lasset({
  // offer a brick asset type that builds a single brick
  async brick({ name }) {
    return `[${name}]`
  },
  // load a wall (and build needed bricks for it)
  async wall({ name }, load) {
    const brickA = await load({ type: 'brick', name: 'a' })
    const brickB = await load({ type: 'brick', name: 'b' })
    return `${name} ${brickA} ${brickB}`
  }
})

// load a wall (and build needed bricks for it)
const wall = await assets.load({ type: 'wall', name: 'WALL' })
// or equivalently
const wall2 = await assets.loaders.wall({ name: 'WALL' })

console.log(wall) //  Outputs WALL [a] [b]
console.log(wall2) // Outputs WALL [a] [b] too since

// invalidate the wall asset using its cache key
assets.invalidate({type: 'wall', name: 'WALL'}) 
await assets.load({type: 'wall', name: 'WALL'}) // causes wall/WALL to be rebuilt but not brick/a or brick/b

assets.invalidate({type: 'brick', name: 'a'}) 
await assets.load({type: 'wall', name: 'WALL'}) // causes brick/a and wall/WALL to be rebuilt but not brick/b
0.4.0

7 months ago

0.3.1

1 year ago

0.3.0

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago