kopia lustrzana https://github.com/shoelace-style/shoelace
only run handler after first render
rodzic
7fb1a83788
commit
c5614bfc95
|
@ -11,6 +11,7 @@ _During the beta period, these restrictions may be relaxed in the event of a mis
|
|||
- Add touch support to `sl-rating` [#362](https://github.com/shoelace-style/shoelace/pull/362)
|
||||
- Fixed a bug where the `open` attribute on `sl-details` would prevent it from opening [#357](https://github.com/shoelace-style/shoelace/issues/357)
|
||||
- Fixed event detail type parsing so component class names are shown instead of `default`
|
||||
- Improved `@watch` decorator so watch handlers don't run before the first render
|
||||
|
||||
## 2.0.0-beta.30
|
||||
|
||||
|
|
|
@ -86,6 +86,9 @@ export function tag(tagName: string) {
|
|||
|
||||
// @watch decorator
|
||||
//
|
||||
// Runs when an observed property changes, e.g. @property or @internalProperty. This will only run after the first
|
||||
// update, so initial values will not trigger the watch function.
|
||||
//
|
||||
// Usage:
|
||||
//
|
||||
// @watch('propName') handlePropChange(oldValue, newValue) {
|
||||
|
@ -94,10 +97,15 @@ export function tag(tagName: string) {
|
|||
//
|
||||
export function watch(propName: string) {
|
||||
return (protoOrDescriptor: any, name: string): any => {
|
||||
const update = protoOrDescriptor.update;
|
||||
const { firstUpdated, update } = protoOrDescriptor;
|
||||
|
||||
protoOrDescriptor.firstUpdated = function (changedProps: Map<string, any>) {
|
||||
firstUpdated.call(this, changedProps);
|
||||
this.__didFirstUpdate = true;
|
||||
};
|
||||
|
||||
protoOrDescriptor.update = function (changedProps: Map<string, any>) {
|
||||
if (changedProps.has(propName)) {
|
||||
if (this.__didFirstUpdate && changedProps.has(propName)) {
|
||||
const oldValue = changedProps.get(propName);
|
||||
const newValue = this[propName];
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue