Releases: choojs/nanocomponent
v6.2.0
v6.1.0
- Added: nanotiming timings. You can name component instances and it will emit timing information. See nanocomponent/pull/47
v6.0.1
- Fixed: [
f9f7540415] - load & unload callbacks should be passed el (timwis)
v6.0.0
π nanocomponent and cache-component are merged into one module: [email protected] π.
Be sure to read the README so that you get an understanding of the new API, but here is a quick summary of what has changed from the perspective of both modules:
Changes since cache-component@5
nanocomponent@6 is mostly the same as cache-component@5 except a few methods are renamed and everything you interact with has had the _ prefix removed.
- Breaking: The
_elementgetter is renamed toelement. - Breaking:
_willMountis renamed tobeforerenderbecause DOM mounting can't be guaranteed from the perspective of a component. - Breaking:
_didMountis removed. Consider usingloadinstead now. - Breaking:
_updateis renamed toupdateand should always be implemented. Instead of the old default shallow compare, not implementingupdatethrows. You canrequire('nanocomponent/compare')to implement the shallow compare if you want that still. See below. - Breaking:
_argsis removed.argumentsincreateElementandupdateare already "sliced", so you can simply capture a copy inupdateandcreateElementand use it for comparison at a later time. - Breaking:
_willUpdateis removed. Anything you could do in_willUpdateyou can just move toupdate. - Changed:
_didUpdateis renamed toafterupdate. It also receives an element argumentele.g.afterupdate(el). This makes its argument signature consistent with the other life-cycle methods. - Added: Added on-load hooks
loadandunload. on-load listeners only get added when one or both of the hooks are implemented on a component making the mutation observers optional.
cache-component@5 to nanocomponent@6 upgrade guide:
- Renamed
_rendertocreateElement. - You must implement
updatenow. Rename existing_updatemethod toupdate. Here is an example of doing shallow compare on components that didn't implement their own update function previously:
var html = require('choo/html')
var Component = require('nanocomponent')
var compare = require('nanocomponent/compare')
class Meta extends Component {
constructor () {
super()
this.arguments = []
}
createElement (title, artist, album) {
this.arguments = arguments // cache a copy of arguments
return html`
<div>
<p>${title}</p>
<p>
${artist} - ${album}
</p>
</div>
`
}
// Implement this to recreate cache-component@5
// behavior when update was not implemented
update () {
return compare(arguments, this.arguments)
}
}- Rename components with
_willMounttobeforerender - Move any
_didMountimplementations intoloador awindow.requestAnmimationFrameinside ofbeforerender. - Move any
_willUpdateimplementations intoupdate. - Rename
_didUpdatetoafterupdate. - Take advantage of
loadandunloadfor DOM insertion aware node interactions π
Changes since nanocomponent@5
nanocomponent@6 has some subtle but important differences from nanocompnent@5. Be sure to read the README and check out the examples to get an understanding of the new API.
- Breaking: The
_elementproperty is removed. A getter calledelementis now used instead. Since this is now a read-only getter, you must not assign anything to this property or else bad things will happen. Theelementgetter returns the component's DOM node if mounted in the page, andundefinedotherwise. You are allowed to mutate that DOM node by hand however. Just don't reassign the property on the component instance. - Fixed: Components can gracefully be removed, re-ordered and remounted between views. You can even mutate the same component over individual instances. This is an improvement over
nanocomponent@5. - Breaking:
_renderis renamed tocreateElementand must now return a DOM node always. In earlier versions you could get away with not returning from_renderand assigning nodes to_element. No longer! Also, you should move your DOM mutations intoupdate. - Changed: Update still works the same way: return true to run
createElementor return false to skip a call tocreateElementwhenrenderis called. If you decide to mutateelement"by hand" on updates, do that here (rather than conditional paths insidecreateElement). - Changed:
_loadand_unloadrenamed toloadandunload. They have always been optional, but now the mutation observers are only added if at least one of these methods are implemented prior to component instantiation. - Added:
beforerenderlifecycle hook. Its similar toloadbut runs before the function call torenderreturns on unmounted component instances. This is where the on-load listeners are added and is a good opportunity to add any other lifecycle hooks. - Added:
afterupdateruns afterupdatereturns true and the results ofcreateElementis mutated over the mounted component. Useful for adjusting scroll position.
nanocomponent@5 to nanocomponent@6 upgrade guide:
- Read through the new leaflet example to get an idea of the differences between the old and new API. πΊ
- Renamed
_rendertocreateElementand_updatetoupdate. - Move any DOM mutation code from
createElementintoupdate. - Ensure
createElementreturns a DOM node always. (You will get warnings if you don't and it probably won't work) - Rename
_loadand_unloadtoloadandunload. - Consider moving any
loadactions intobeforerenderif they don't depend on the newly rendered node being mounted in a DOM tree yet. - Take advantage of
afterupdateallowing you to interact with your component aftercreateElementis called on mounted components π
6.0.0-1
Beta release. See CHANGELOG draft: https://github.com/choojs/nanocomponent/blob/v6.0.0-1/CHANGELOG.md
6.0.0-0
Beta release!
See CHANGELOG draft: https://github.com/choojs/nanocomponent/blob/v6.0.0-0/CHANGELOG.md