ember.js - Ember's volatile and templates -


i have property mood part of interface component. behind scenes have computed property called _mood:

const { computed, typeof } = ember; _mood: computed('mood','a','b','c' function() {   let mood = this.get('mood');   if (typeof(mood) === 'function') {     mood = mood(this);   }   return !mood || mood === 'default' ? '' : `mood-${mood}`; }).volatile(), 

i have situation volatile() hangs of of ember's computed object resolves non dom unit tests reason not triggering template update dom under circumstance. should, @ least, update if of properties being watched change (in case ['mood','a', 'b', 'c']) change. because volatile (aka, doesn't cache results) new results show in template if template knew re-render component reason doesn't.

if remove volatile() tag works fine static/scalar values if mood function result cached , therefore works once (not working solution problem).

how best of both worlds?

i'm still not sure why volatile() method turning off updates templates. might real bug in terms of solving problem important thing recognise volatile approach never best approach.

instead important thing ensure when mood comes in function function's dependencies included in cp's dependencies. so, instance, if mood passed following function:

mood: function(context) {    return context.title === 'monkeys' ? 'happy' : 'sad';  } 

for function evaluate -- , more importantly trigger re-evaluation @ right time -- title property must part of computed property. that's straight forward why here's how thought might accommodated this:

_mooddependencies: ['title','subheading','style'], _mood: computed('mood','size','_mooddependencies', function() {   let mood = this.get('mood');   console.log('mood is: %o', mood);   if (typeof(mood) === 'function') {     run( ()=> {       mood = mood(this);     });   }   return !mood || mood === 'default' ? '' : `mood-${mood}`; }), 

that's better, allows @ build time static set of properties defined per component (the _mood cp me part of mixin used few components). unfortunately doesn't yet work apparently doesn't unpack/destructure _mooddependencies.

i'll sorted , update unless else beats me punch.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -