github cyclejs/cyclejs v0.17.0
v0.17.0 - View rejects custom element as root

latest releases: unified-tag, v7.0.0, v7.0.0-rc8...
pre-release9 years ago

This version changes the contract in Cycle so that the DOMUser throws an error if it is injected a View that has a Cycle custom element at the root.

THIS IS NOW REJECTED:

let View = Cycle.createView(Model => ({
  vtree$: Model.get("active$").map(active =>
    h('mycustomelement', {active: active}) // <== here
  }),
}));

YOU NEED TO WRAP IT:

let View = Cycle.createView(Model => ({
  vtree$: Model.get("active$").map(active =>
    h('div', [ // <== here
      h('mycustomelement', {active: active})
    ])
  }),
}));

The rationale behind this is two-fold:

  1. This isn't a priority as a feature at the moment. Custom element at the root was considered a bug (#89), and it was partially fixed. More problems related to this recently appeared, and the solution was getting complicated since it's deep into virtual-dom's diff and patch, Widgets, custom elements, etc. I prefer to explicitly not support this use case, then to either have it buggy or to spend a lot of time fixing it. The good news is that later on (maybe post-1.0) it is easy to add support for custom element at the root, while staying backwards compatible (you will also be able to keep on using the div wrapper). In other words, rather do a breaking change now.
  2. A custom element alone in the View is a code smell. If you only have the custom element, then why do you need the View wrapping the custom element? I currently can't see how custom element as the single element in a View is a meaningful pattern. But anyway, if someone discovers this is genuinely important use case, then read argument (1) above where we can add in the future support for this without introducing a breaking change.

Additional small feature:
You can listen to DOMUser errors on user.get('error$').

Don't miss a new cyclejs release

NewReleases is sending notifications on new releases.