Migrating from 0.8 to 0.9
Breaking Changes
Routing Changes
NodeCG's routing has always been a little arbitrary and confusing. It did not match the structure of the filesystem, and there wasn't really a good reason for this. This arbitrary routing structure was hard to remember and prevented bundle authors from taking advantage of their IDE's autocomplete functionality. It also made using filesystem-aware tools like the polymer-bundler
(formerly called vulcanize
) needlessly difficult.
The new routing structure matches the structure of the filesystem, making routes easier to work with and avoiding certain bugs relating to the de-duplication of HTML Imports (and soon, ES Modules).
Old (don't use these anymore!):
/panels/my-bundle/panel.html
/graphics/my-bundle/graphic.html
# Two different routes to the same file! This breaks the de-duplication of HTML Imports and causes errors.
/panels/my-bundle/components/polymer/polymer.html
/graphics/my-bundle/components/polymer/polymer.html
New:
/bundles/my-bundle/dashboard/panel.html
/bundles/my-bundle/graphics/graphic.html
# Now, there is only one single route to any given file.
/bundles/my-bundle/bower_components/polymer/polymer.html
Removed Default Styles
Up until now, NodeCG has injected some default styles and helper classes into each and every panel. The idea was to provide a set of base styles that every bundle author could use to try to create a cohesive NodeCG panel design across all bundles.
However, this set of styles was far too small and limited to achieve that, and upon further reflection we decided that NodeCG core was not the place to attempt to accomplish this. Additionally, it's possible for these injected styles to cause frustrating conflicts.
NodeCG does still inject a few default styles, but the number of styles has been dramatically reduced to just a few necessary things, such as the background color for panels. And, as always, this value can be easily overridden in your panel's CSS.
If your panels relied on any of these default styles or helper classes such as nodecg-configure
, you will need to manually specify new styles instead.
sendMessage acknowledgement Errors
In the past, if you tried to reply to a sendMessage
with an Error
, you'd end up with just an empty Object at the other end ({}
). This is because by default, JavaScript Error
s are serialized as an empty Object by JSON.stringify
.
Now, if the first argument to a sendMessage
acknowledgement is an error, it will be properly serialized and sent across the wire. As part of this, we are now strongly encouraging that all sendMessage
acknowledgements always be treated as standard error-first Node.js-style callbacks.
In addition, client-side sendMessage
now also returns a Promise
, so that you may use .then
/.catch
instead of a callback function. See the updated sendMessage
documentation for more information.
Please note that if you do not specify a callback to your sendMessage
, then it will always return a Promise. Additionally, the first argument sent back in your acknowledgement is always assumed to be either an Error
or null
. If this value is truthy, then it will be used to reject
the Promise. For this reason, it is strongly encouraged that all sendMessage
acknowledgements strictly adhere to the error-first style of callbacks.