Detalhes do pacote

tracked-built-ins

tracked-tools332.8kMIT4.0.0

Tracked versions of JavaScript's built-in classes!

ember-addon

readme (leia-me)

tracked-built-ins GitHub Actions Build Status

This addon provides tracked versions of JavaScript's built-ins:

import {
  TrackedObject,
  TrackedArray,
  TrackedMap,
  TrackedSet,
  TrackedWeakMap,
  TrackedWeakSet,
} from 'tracked-built-ins';

These classes have the same APIs as their native equivalents, but reading from them or writing to them will be tracked, allowing you to use them in your Ember apps and have changes automatically propagate!

Also included is an enhanced version of the @tracked decorator, which automatically shallow-wraps the native versions of these classes:

import { tracked } from 'tracked-built-ins';

class Foo {
  @tracked value = 123;

  obj = tracked({});
  arr = tracked([]);
  map = tracked(Map);
  set = tracked(Set);
  weakMap = tracked(WeakMap);
  weakSet = tracked(WeakSet);
}

Note: This addon does NOT support IE 11 or older browsers. If you need to support them, consider using tracked-maps and sets instead.

Installation

ember install tracked-built-ins

Usage

See the MDN documentation for each class to learn more about it:

All public APIs are the same, with a few exceptions:

  1. new TrackedArray() should receive an array instead of variable number of arguments. This decision was due to the confusing nature of new Array() in general, and for symmetry with the other new APIs.

    // bad
    new TrackedArray(123);
    new TrackedArray('foo', 'bar', 'baz');
    
    // good
    new TrackedArray([123]);
    new TrackedArray(['foo', 'bar', 'baz']);
    
  2. new TrackedObject() returns a copy of the object passed back to it, whereas new Object() will return the original object. This is to prevent accidentally mutating the original object.

    let original = {};
    let obj = new TrackedObject(original);
    
    obj.foo = 123;
    original.foo; // undefined;
    
  3. Static Array and Object methods that do not create a new Array/Object have been omitted. In general, you should use the original static methods for these features, since autotracking has nothing to do with them. The static methods that are supported are:

    • Array
      • from
      • of
    • Object
      • fromEntries

    Object.create has also been omitted, even though it creates an instance, because manual prototype manipulation is an advanced use case in general that is not currently supported.

All types will also register as instanceof their base type, so they can be used as fully transparent replacements in most circumstances.

Compatibility

  • Ember.js v3.28 (LTS) or above
  • Embroider v3 and greater or ember-auto-import v2.7.0 and greater

TypeScript

This project follows the current draft of the Semantic Versioning for TypeScript Types specification.

  • Currently supported TypeScript versions: 5.5, 5.6, and 5.7
  • Compiler support policy: simple majors
  • Public API: all published types not in a -private module are public

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.

changelog (log de mudanças)

Changelog

Release (2025-01-17)

tracked-built-ins 4.0.0 (major)

:boom: Breaking Change

:rocket: Enhancement

  • tracked-built-ins, test-app

:memo: Documentation

Committers: 3

Release (2024-12-02)

tracked-built-ins 3.4.0 (minor)

:rocket: Enhancement

  • tracked-built-ins, test-app

:bug: Bug Fix

:house: Internal

Committers: 3

v3.3.0 (2023-09-22)

:rocket: Enhancement

  • #408 Move Array#fill to "write then read" methods so the template correctly updates (@locks)

:memo: Documentation

:house: Internal

  • #409 Update test-app to the latest blueprint (@ef4)

Committers: 4

v3.2.0 (2023-01-30)

:rocket: Enhancement

:bug: Bug Fix

  • #397 Fix incorrect mutation-after-consumption assertions for Array push and unshift (@chriskrycho)

:house: Internal

Committers: 4

v3.1.1 (2023-01-31)

:bug: Bug Fix

  • #402 Backport: Introduce flag for length access after push/unshift (@chriskrycho)

Committers: 1

v3.1.0 (2022-05-17)

:rocket: Enhancement

  • #30 Trigger update after calling delete on an object property (@lifeart)

:bug: Bug Fix

:house: Internal

Committers: 2

v3.0.0 (2022-05-17)

:boom: Breaking Change

  • #330 Drop support for Node 12 (@chriskrycho)
  • for supporting Ember v4, now requires ember-auto-import v2

:rocket: Enhancement

:bug: Bug Fix

:memo: Documentation

:house: Internal

  • #305 Additional TrackedArray test to ensure that clearing the array by setting length = 0 is possible. (@ksrb)
  • #321 Directly integrate tracked maps and sets (@chriskrycho)

Committers: 3

v2.0.1 (2021-12-17)

:bug: Bug Fix

Committers: 1

v2.0.0 (2021-11-11)

:boom: Breaking Change

:rocket: Enhancement

:memo: Documentation

:house: Internal

Committers: 3

v1.1.1 (2021-04-23)

:bug: Bug Fix

  • #42 [Bug]: resolve error in build without browsers in targets.js file (@snewcomer)

:house: Internal

Committers: 2

v1.1.0 (2021-04-23)

:rocket: Enhancement

:house: Internal

Committers: 2

v1.0.2 (2020-04-24)

:bug: Bug Fix

  • #25 [BUGFIX] Fixes the mandatory setter bug (@pzuraq)

Committers: 1

v1.0.1 (2020-03-25)

:bug: Bug Fix

  • #22 [BUGFIX] Ensure key operators work for TrackedObject (@pzuraq)
  • #20 Update decorator.ts (@speigg)

Committers: 2

v1.0.0 (2020-03-18)

:boom: Breaking Change

  • #16 [FEAT] Adds TrackedArray and TrackedObject (@pzuraq)
  • #13 [REFACTOR] Extracts Maps and Sets, updates decorator (@pzuraq)

:rocket: Enhancement

  • #18 [FEAT] Adds release process and changelog (@pzuraq)
  • #17 [FEAT] Adds error when attempting to use in IE11 (@pzuraq)
  • #15 [REFACTOR] Better decorator types (@pzuraq)

Committers: 1