Last active
December 27, 2019 14:12
-
-
Save pzuraq/1f5043aecd771df5768f85fa9d3b67eb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { TrackedWeakMap } from 'tracked-built-ins'; | |
function localCopy(target, key) { | |
let values = new TrackedWeakMap(); | |
let lastValues = new WeakMap(); | |
return { | |
get() { | |
let incoming = this.args[key]; | |
let lastValue = lastValues.get(this); | |
if (lastValue !== incoming) { | |
values.set(this, incoming); | |
lastValues.set(this, incoming); | |
} | |
return values.get(this); | |
}, | |
set(value) { | |
values.set(this, value); | |
} | |
} | |
} | |
class MyComponent extends Component { | |
@localCopy myValue; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyComponent extends Component { | |
@tracked _myValue; | |
get myValue() { | |
let incoming = this.args.myValue; | |
let lastValue = this._lastValue; | |
if (lastValue !== incoming) { | |
this._myValue = this._lastValue = incoming; | |
} | |
return this._myValue; | |
} | |
set myValue(value) { | |
this._myValue = value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment