# new Tracked(initialValueopt)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
initialValue |
any |
<optional> |
an optional initial value for this Tracked instance |
Members
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 |
the owner
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() |
# 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 |
the cached (or newly cached) Tracked instance for the associated property and owner
# 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. |
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.
# dirty()
Will dirty this Tracked instance. It will not change the value.