Class

Tracked

tracking.Tracked(initialValueopt)

Represents a value that is tracked. When the value is set it will dirty itself and schedule a render (if applicable). The dirty-ness is taken into account when an instance of Cache consumes and instance of Tracked.

Constructor

# new Tracked(initialValueopt)

Parameters:
Name Type Attributes Description
initialValue any <optional>

an optional initial value for this Tracked instance

View Source tracking.js, line 24

Members

# revision

Properties:
Name Type Description
the number

latest revision number for this Tracked

View Source tracking.js, line 28

# value

This is the property to access the tracked value. Reading this property will consume it. Setting this property will dirty it.

Properties:
Type Description
any

View Source tracking.js, line 45

Methods

# static activate() → {Object}

Loop over the properties of the owner and any properties that are a Tracked instance convert them to a getter/setter.

Properties:
Name Type Description
owner Object

the object er want to convert all Tracked values to a getter/setter

View Source tracking.js, line 168

the owner

Object
Examples
class Foo {
  bar = new Tracked();
}
let foo = Tracked.activate(new Foo());
foo.bar = 'BAR'; // will trigger a render (becomes dirty)
let obj = Tracked.activate({ bar: new Tracked('FOO') });
foo.bar = 'BAR'; // will trigger a render (becomes dirty)

# static defineProperty()

Will define a property on an owner that is tracked.

let obj = {};
Tracked.defineProperty(obj, 'foobar', new Tracked('FOO'));

Is the same as

let obj = Tracked.activate({
  foobar: new Tracked('FOO')
});
Properties:
Name Type Attributes Description
owner Object

the object that we want to define a property on

prop string

the property name we want to define

tracked Tracked <optional>

a Tracked instance. Default is new Tracked()

View Source tracking.js, line 138

# static for() → {Tracked}

Grab a cached Tracked instance for a particular property on a specific owner. This is used to allow tracking of something without modifying the owner itself. Useful for things like getAttribute/setAttribute on DOM nodes.

Properties:
Name Type Attributes Description
owner Object

the object that we want to associate the Tracked with

prop string

the property name we want to associate the Tracked with

initializer function <optional>

a function that returns the Tracked initial value if a Tracked hasn't already been created previously

View Source tracking.js, line 84

the cached (or newly cached) Tracked instance for the associated property and owner

Tracked

# static proxy(owneropt) → {Proxy}

Convenience function to make a proxy over an object such that any access to one of its properties will be tracked.

Parameters:
Name Type Attributes Description
owner Object <optional>

an object to proxy. Default is an empty Object.

View Source tracking.js, line 105

Proxy
Example
let obj = { foo: 'FOO' };
let trackedProxy = Tracked.proxy(obj);
trackedProxy.foo = 'BAR'; // will trigger a render (becomes dirty)
obj.foo = 'BAZ'; // will NOT trigger a render

# consume()

Will mark this as consumed. This does not affect the value property.

View Source tracking.js, line 67

# dirty()

Will dirty this Tracked instance. It will not change the value.

View Source tracking.js, line 59