Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ember-cached-decorator-polyfill

Package Overview
Dependencies
Maintainers
9
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ember-cached-decorator-polyfill

Polyfill for RFC 566: @cached

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
9
Created
Source

ember-cached-decorator-polyfill

CI npm version Download Total Ember Observer Score code style: prettier Dependabot enabled dependencies Status devDependencies Status

Polyfill for RFC 566 "@cached decorator".

Installation

ember install ember-cached-decorator-polyfill

For addons, pass the -S flag.

If you're working in an environment with an explicit Babel config (like a V2 addon or an app with ember-cli-babel's { useBabelConfig: true } mode), see "Explicit Babel Config" below.

Compatibility

  • Ember.js v3.13 or above
  • Ember CLI v2.13 or above
  • Node.js v14 or above

Summary

Add a @cached decorator for memoizing the result of a getter based on autotracking. In the following example, fullName would only recalculate if firstName or lastName is updated.

import { tracked, cached } from '@glimmer/tracking';

class Person {
  @tracked firstName = 'Jen';
  @tracked lastName = 'Weber';

  @cached
  get fullName() {
    return `${this.firstName} ${this.lastName}`;
  }
}

For detailed usage instructions, refer to the RFC 566 "@cached decorator".

TypeScript Usage

TypeScript's normal type resolution for an import from @glimmer/tracking will not find the types provided by this polyfill, since the actual @glimmer/tracking package does not include an export for cache.

In order for TypeScript to recognize the extra cache export, add an import like this somewhere in your codebase (like app.ts or test-helper.ts):

import 'ember-cached-decorator-polyfill';

Once the upstream types have been updated to reflect RFC 566, this will no longer be necessary.

Explicit Babel Config

In environments where you have an explicit Babel config (like authoring a V2 addon) you will need to configure this polyfill's babel plugin. Add it to your babel.config.js like:

{
  "plugins": [
    "ember-cached-decorator-polyfill/babel-plugin"
  ]
}

Keywords

FAQs

Package last updated on 26 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc