Nostradamus Predicting Maelstroms
    Have ideas to improve npm?Join in the discussion! »

    @emotion/weak-memoize
    TypeScript icon, indicating that this package has built-in type declarations

    0.2.5 • Public • Published

    @emotion/weak-memoize

    A memoization function that uses a WeakMap

    Install

    yarn add @emotion/weak-memoize

    Usage

    Because @emotion/weak-memoize uses a WeakMap the argument must be a non primitive type, e.g. objects, functions, arrays and etc. The function passed to weakMemoize must also only accept a single argument.

    import weakMemoize from '@emotion/weak-memoize'
     
    let doThing = weakMemoize(({ someProperty }) => {
      return { newName: someProperty }
    })
     
    let obj = { someProperty: true }
     
    let firstResult = doThing(obj)
     
    let secondResult = doThing(obj)
     
    firstResult === secondResult // true
     
    let newObj = { someProperty: true }
     
    let thirdResult = doThing(newObj)
     
    thirdResult === firstResult // false

    Keywords

    none

    Install

    npm i @emotion/weak-memoize

    DownloadsWeekly Downloads

    3,926,737

    Version

    0.2.5

    License

    MIT

    Unpacked Size

    8.03 kB

    Total Files

    16

    Last publish

    Collaborators

    • avatar
    • avatar
    • avatar
    • avatar