
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
ember-computed-change-gate
Advanced tools
Create computed properties which trigger observers only if the value of the computed property has changed
Observers on Ember.js computed properties are fired if a dependant key changes, regardless of whether the property value changes or not. ember-computed-change-gate
only triggers observers when the result of a computed property changes.
Consider the following example:
Ember.Object.extend({
name: 'Gavin',
trimmedName: Ember.computed('name'), function() {
return this.get('name').trim();
}),
onTrimmedNameChanged: Ember.observer('trimmedName', function() {
console.log('trimmedName changed');
})
});
Every time name
changes onTrimmedNameChanged
will be run, even if the value of trimmedName
doesn't change.
import changeGate from 'ember-computed-change-gate/change-gate';
Ember.Object.extend({
name: 'Gavin',
trimmedName: changeGate('name', function(value) {
return value.trim();
}),
onTrimmedNameChanged: Ember.observer('trimmedName', function() {
console.log('trimmedName changed');
})
});
Using changeGate
will prevent the onTrimmedNameChanged
observer from firing unless the value of trimmedName
changes. Please see the video below for an example of how I've used this when building Intercom:
Since Ember 3.11 extra configuration can be passed to observers to allow them to be configured synchronous or asynchronous. To configure the synchronous state of the observer in changeGate
pass a config object as the last param with the sync
property set appropriately.
For example:
// synchronous observer
trimmedName: changeGate('name', function(value) {
return value.trim();
}, { sync: true }),
//asynchronous observer
trimmedName: changeGate('name', function(value) {
return value.trim();
}, { sync: false }),
See this RFC and blog post for more informationa about async observers.
Questions? Ping me @gavinjoyce
This is an Ember CLI addon, to install:
ember install ember-computed-change-gate
git clone
this repositorynpm install
bower install
npm run lint:js
npm run lint:js -- --fix
ember test
– Runs the test suite on the current Ember versionember test --server
– Runs the test suite in "watch mode"ember try:each
– Runs the test suite against multiple Ember versionsember serve
For more information on using ember-cli, visit https://ember-cli.com/.
This project is licensed under the MIT License.
FAQs
Create computed properties which trigger observers only if the value of the computed property has changed
The npm package ember-computed-change-gate receives a total of 275 weekly downloads. As such, ember-computed-change-gate popularity was classified as not popular.
We found that ember-computed-change-gate demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.