Last active
August 4, 2020 14:09
-
-
Save amessinger/e1ac5175bfa89b439902adf84500b27b to your computer and use it in GitHub Desktop.
Observer
This file contains 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 { tracked } from '@glimmer/tracking'; | |
import Component from '@ember/component'; | |
import { action, computed, observer } from '@ember/object'; | |
export default class extends Component { | |
updateActiveItem = observer('activeItems', function() { | |
console.log('updateActiveItem'); | |
this.isActive = this.activeItems.includes(this.item); | |
}) | |
@action | |
setActive(event) { | |
console.log('setActive'); | |
event.preventDefault(); | |
if (this.activeItems.includes(this.item)) { | |
this.activeItems.removeObject(this.item); | |
} else { | |
this.activeItems.pushObject(this.item); | |
} | |
console.log(this.activeItems, this.activeItems.length); | |
} | |
} |
This file contains 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 Component from '@ember/component'; | |
import { observer } from '@ember/object'; | |
export default class extends Component { | |
updateActiveItem = observer('activeItems.[]', function() { | |
console.log('parent updateActiveItem'); | |
}) | |
} |
This file contains 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 Controller from '@ember/controller'; | |
import { A } from '@ember/array'; | |
export default class ApplicationController extends Controller { | |
appName = 'Ember Twiddle'; | |
items = A([1, 2, 3, 4]); | |
activeItems = A([1, 2]); | |
} |
This file contains 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
{ | |
"version": "0.17.1", | |
"EmberENV": { | |
"FEATURES": {}, | |
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false, | |
"_APPLICATION_TEMPLATE_WRAPPER": true, | |
"_JQUERY_INTEGRATION": true | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js", | |
"ember": "3.18.1", | |
"ember-template-compiler": "3.18.1", | |
"ember-testing": "3.18.1" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment