You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*`nextValue` - a value of the current state of the property
68
+
-**arguments**:
69
+
-`host` - an element instance
70
+
-`lastValue` - last cached value of the property
71
+
-**returns (required)**:
72
+
-`nextValue` - a value of the current state of the property
73
73
74
74
`get` calculates the current property value. The returned value is always cached. The cache mechanism works between properties defined by the library (even between different elements). If your `get` method does not use other properties, it won't be called again (then, the only way to update the value is to assert new value or call `invalidate` from `connect` method).
75
75
@@ -79,8 +79,8 @@ In the following example, the `get` method of the `name` property is called agai
*`value` - a value passed to assertion (ex., `el.myProperty = 'new value'`)
108
-
*`lastValue` - last cached value of the property
109
-
***returns (required)**:
110
-
*`nextValue` - a value of the property, which replaces cached value
105
+
-**arguments**:
106
+
-`host` - an element instance
107
+
-`value` - a value passed to assertion (ex., `el.myProperty = 'new value'`)
108
+
-`lastValue` - last cached value of the property
109
+
-**returns (required)**:
110
+
-`nextValue` - a value of the property, which replaces cached value
111
111
112
112
Every assertion of the property calls `set` method (like `myElement.property = 'new value'`). If returned `nextValue` is not equal to `lastValue`, cache of the property invalidates. However, `set` method does not trigger `get` method automatically. Only the next access to the property (like `const value = myElement.property`) calls `get` method. Then `get` takes `nextValue` from `set` as the `lastValue` argument, calculates `value` and returns it.
113
113
@@ -118,7 +118,7 @@ const MyElement = {
118
118
power: {
119
119
set: (host, value) => value ** value,
120
120
},
121
-
}
121
+
};
122
122
123
123
myElement.power=10; // calls 'set' method and set cache to 100
*`invalidate` - a callback function, which invalidates cached value
149
-
***returns (not required):**
150
-
*`disconnect` - a function (without arguments)
145
+
-**arguments**:
146
+
-`host` - an element instance
147
+
-`key` - a property key name
148
+
-`invalidate` - a callback function, which invalidates cached value
149
+
-**returns (not required):**
150
+
-`disconnect` - a function (without arguments)
151
151
152
152
When you insert, remove or relocate an element in the DOM tree, `connect` or `disconnect` is called synchronously (in the `connectedCallback` and `disconnectedCallback` callbacks of the Custom Elements API).
153
153
@@ -156,21 +156,21 @@ You can use `connect` to attach event listeners, initialize property value (usin
156
156
If the third party code is responsible for the property value, you can use `invalidate` callback to notify that value should be recalculated (within next access). For example, it can be used to connect to async web APIs or external libraries:
When property cache invalidates (directly by the assertion or when one of the dependency invalidates) and `observe` method is set, the change detection mechanism adds the property to the internal queue. Within the next animation frame (using `requestAnimationFrame`) properties from the queue are checked if they have changed, and if they did, `observe` method of the property is called. It means, that `observe` method is asynchronous by default, and it is only called for properties, which value is different in the time of execution of the queue (in the `requestAnimationFrame` call).
0 commit comments