// Unminified
import { tracked } from 'https://fancy-pants.js.org/tracking.js';
// Minified
import { tracked } from 'https://fancy-pants.js.org/min/tracking.js';
This is the auto-tracking system and a use case for
scheduleRender
.
Classes
Methods
# static activateTracking(owner) → {Object}
This is how all tracked
properties are
converted from the place holder TrackedProperty object into actual tracked
getter/setters. Any object that uses tracked
must be passed through activateTracking
otherwise the properties are
useless.
Parameters:
Name | Type | Description |
---|---|---|
owner |
Object | the object to search and replace any Tracked objects. |
the same owner object passed in to support chaining
Examples
class Foo {
bar = tracked();
}
let foo = activateTracking(new Foo());
foo.bar = 'BAR'; // will trigger a render (becomes dirty)
let obj = activateTracking({ bar: tracked('FOO') });
foo.bar = 'BAR'; // will trigger a render (becomes dirty)
# static memoizeFunction(fn) → {function}
Wrap a function to be memoized based on the auto-tracking system.
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | the function to memoized |
a memoized version of the function
# static setScheduleRerender(callback)
Register a function to be called when a Tracked instance is dirtied.
There can only be one. This is not used when working with the
renderer
or Component
class as they mange
this for you.
You would only use this if you were interfacing with this module on your own.
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | the function to call when tags are dirtied |
# static tracked(initialValueopt) → {Tracked}
Create a Tracked instance.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
initialValue |
any |
<optional> |
Examples
class Foo {
bar = tracked();
}
let foo = new Foo();
foo.bar.revision; // 0
foo.bar.value = 'BAR';
foo.bar.revision; // 1
let foo = { bar: tracked('FOO') };
foo.bar.revision; // 0
foo.bar.value = 'BAR';
foo.bar.revision; // 1