ember-cache-primitive-polyfill

1.0.1 • Public • Published

ember-cache-primitive-polyfill

Polyfills Ember's cache primitive API.

Provides a low-level primitive for memoizing the result of a function based on autotracking, allowing users to create their own reactive systems that can respond to changes in autotracked state.

Compatibility

  • Ember.js v3.13 or above (inert for Ember 3.22+)
  • ember-cli-babel v7.22.1 or above
  • Ember CLI v3.8 or above
  • Node.js v10 or above

Installation

ember install ember-cache-primitive-polyfill

Usage

import { tracked } from '@glimmer/tracking';
import { createCache, getValue } from '@glimmer/tracking/primitives/cache';
 
let computeCount = 0;
 
class Person {
  @tracked firstName = 'Jen';
  @tracked lastName = 'Weber';
 
  #fullName = createCache(() => {
    ++computeCount;
    return `${this.firstName} ${this.lastName}`;
  })
 
  get fullName() {
    return getValue(this.#fullName);
  }
}
 
let person = new Person();
 
console.log(person.fullName); // Jen Weber
console.log(count); // 1;
console.log(person.fullName); // Jen Weber
console.log(count); // 1;
 
person.firstName = 'Jennifer';
 
console.log(person.fullName); // Jennifer Weber
console.log(count); // 2;

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.

Readme

Keywords

Package Sidebar

Install

npm i ember-cache-primitive-polyfill

Weekly Downloads

77,499

Version

1.0.1

License

MIT

Unpacked Size

15.3 kB

Total Files

9

Last publish

Collaborators

  • mmun
  • simonihmig
  • pzuraq
  • rwjblue