dojo / widget-core

:rocket: Dojo 2 - widget authoring system.
http://dojo.io
Other
34 stars 39 forks source link

How do you animate with nodes across widgets? #955

Closed schontz closed 6 years ago

schontz commented 6 years ago

I have an app that looks something like:

App
|- Header
   |- Home icon
   |- Cart icon
|- Main: (Home OR Search OR ...)
   |- Item
   |- Item
   |- Item ...

When you click a button on an Item to add it to the cart I want to do the following:

  1. Create an icon/avatar
  2. Move that avatar from the source button to the Cart icon in the Header widget
  3. And then perform some action on the Cart icon, e.g. wiggle the cart and +1 the quantity in an animated fashion.

In a reactive app you cannot dig into widgets directly or look at their nodes. What is an elegant way to perform this action? My thought process:

My solution requires me to explicitly bubble the event all the way up to the App top level through each widget. That is not ideal and brittle. I also happen to be using a Container around my Items so I added some logic in the container widget which is also not ideal.

In my example, if the child widget could set a value on an app-level registry that would make things easier. I don't know if this is the right way(TM), but to get the discussion going...

// Source widget
w(Item, { onAddToCart: (e: MouseEvent) => this.appGlobal.set('addToCart', e) });

// Consuming widget
w(Cart, { addToCartEvented: this.appGlobal.getOnChange('addToCart') });

While my cart example is specific, I think there are some generalities that people coming from dojo 1/non-reactive design will run into:

dylans commented 6 years ago

I'm going to move this to dojo/meta, as this is an issue that somewhat transcends multiple packages/repos.

dylans commented 6 years ago

Issue moved to dojo/meta #260 via ZenHub