All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.
- You can modify makeID (#96)
- Fix
onclick
event name in readme example (#82) - Add doc note about maintaining control of a component (#89)
- Point out the
createElement()
return value should be a single DOM node (#93)
- Allow SVGs as the root node (#79)
- Update deps
- Update [email protected]
- Update devdeps: tap-run, dependency-check, browserify, bankai
- Proxy elements are created matching the root node returned from the
createElement
method. (🙏@tornqvist🙏)
- Pin
on-load
to v3.3.4 to fix node import.
- Pin
on-load
to v3.3.3 to fix unbundled electron import.
- Pin
on-load
to 3.3.2 to fix unbundled electron import.
- Fixed
afterreorder
hook typo. - Update
on-load
to handle<head>
loading and for addded assertions.
- Added:
.rerender()
method to allow re-rendering with the last rendered arguments if internal state changes. - Updated docs for
rerender
. - Add a few more pitfall pointers in the lifecycle API docs around rerendering in
beforerender
.
- Added: Use
nanoassert
in the browser.
- Added:
afterreorder
event which is called after your component is remounted on sibbling reorders.
- Added: nanotiming timings. You can name component instances and it will emit timing information. See nanocomponent/pull/47
- Fixed: [
f9f7540415
] - load & unload callbacks should be passed el (timwis)
🎉 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:
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
_element
getter is renamed toelement
. - Breaking:
_willMount
is renamed tobeforerender
because DOM mounting can't be guaranteed from the perspective of a component. - Breaking:
_didMount
is removed. Consider usingload
instead now. - Breaking:
_update
is renamed toupdate
and should always be implemented. Instead of the old default shallow compare, not implementingupdate
throws. You canrequire('nanocomponent/compare')
to implement the shallow compare if you want that still. See below. - Breaking:
_args
is removed.arguments
increateElement
andupdate
are already "sliced", so you can simply capture a copy inupdate
andcreateElement
and use it for comparison at a later time. - Breaking:
_willUpdate
is removed. Anything you could do in_willUpdate
you can just move toupdate
. - Changed:
_didUpdate
is renamed toafterupdate
. It also receives an element argumentel
e.g.afterupdate(el)
. This makes its argument signature consistent with the other life-cycle methods. - Added: Added on-load hooks
load
andunload
. on-load listeners only get added when one or both of the hooks are implemented on a component making the mutation observers optional.
- Renamed
_render
tocreateElement
. - You must implement
update
now. Rename existing_update
method 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
_willMount
tobeforerender
- Move any
_didMount
implementations intoload
or awindow.requestAnmimationFrame
inside ofbeforerender
. - Move any
_willUpdate
implementations intoupdate
. - Rename
_didUpdate
toafterupdate
. - Take advantage of
load
andunload
for DOM insertion aware node interactions 🙌
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
_element
property is removed. A getter calledelement
is 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. Theelement
getter returns the component's DOM node if mounted in the page, andundefined
otherwise. 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:
_render
is renamed tocreateElement
and must now return a DOM node always. In earlier versions you could get away with not returning from_render
and 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
createElement
or return false to skip a call tocreateElement
whenrender
is called. If you decide to mutateelement
"by hand" on updates, do that here (rather than conditional paths insidecreateElement
). - Changed:
_load
and_unload
renamed toload
andunload
. 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:
beforerender
lifecycle hook. Its similar toload
but runs before the function call torender
returns 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:
afterupdate
runs afterupdate
returns true and the results ofcreateElement
is mutated over the mounted component. Useful for adjusting scroll position.
- Read through the new leaflet example to get an idea of the differences between the old and new API. 🗺
- Renamed
_render
tocreateElement
and_update
toupdate
. - Move any DOM mutation code from
createElement
intoupdate
. - Ensure
createElement
returns a DOM node always. (You will get warnings if you don't and it probably won't work) - Rename
_load
and_unload
toload
andunload
. - Consider moving any
load
actions intobeforerender
if they don't depend on the newly rendered node being mounted in a DOM tree yet. - Take advantage of
afterupdate
allowing you to interact with your component aftercreateElement
is called on mounted components 🙌