ember-animation / ember-animated

Core animation primitives for Ember.
https://ember-animation.github.io/ember-animated/
MIT License
244 stars 90 forks source link

`animated-value` with `undefined` value and key throws error #14

Open nickschot opened 6 years ago

nickschot commented 6 years ago

When using ember-elsewhere you might not always want to provide a defined value (e.g. a page where nothing should be rendered in the elsewhere). Currently when passing an undefined value to an animated-value and at the same time providing a key attribute throws a Assertion Failed: Cannot call get with 'text' on an undefined object.

Seems to be originating from https://github.com/ember-animation/ember-animated/blob/master/addon/components/animated-each.js#L88

ef4 commented 6 years ago

Ah, make sense. I think we would fix this in animated-value. Currently it essentially passes items=[value] to animated-each, but when value is null we should pass items=[].

ef4 commented 6 years ago

My apologies, but now that I think more about it, I was wrong in my comment above.

null is a valid value that you may want to render and animate.

For example:

{{#animated-value myPreference as |pref|}}
  {{#if pref}}
      Your preference is {{pref}}.
   {{else}}
      You have not chosen a preference.
   {{/if}}
{{/animated-value}}

While it would be possible to make animated-value accept its own {{else}} block, that's a complication I would rather avoid, when you can achieve the same thing as above without learning a new concept.

So instead I think we should add guards where we try to use the key property to access properties on the possibly-null value.

Cryrivers commented 6 years ago

@ef4 sure, i will investigate this weekend.