nanocomponent
Advanced tools
Comparing version 3.0.2 to 4.0.0
@@ -7,3 +7,3 @@ var onload = require('on-load') | ||
function Nanocomponent (val) { | ||
this._hasWindow = typeof window !== undefined | ||
this._hasWindow = typeof window !== 'undefined' | ||
this._placeholder = null | ||
@@ -17,2 +17,3 @@ this._onload = onload | ||
assert.equal(typeof this._render, 'function', 'nanocomponent: this._render should be implemented') | ||
assert.equal(typeof this._update, 'function', 'nanocomponent: this._update should be implemented') | ||
@@ -55,7 +56,2 @@ var self = this | ||
// default ._update method - should be replaced with custom logic | ||
Nanocomponent.prototype._update = function () { | ||
return true | ||
} | ||
Nanocomponent.prototype._createPlaceholder = function () { | ||
@@ -62,0 +58,0 @@ var el = document.createElement('div') |
{ | ||
"name": "nanocomponent", | ||
"version": "3.0.2", | ||
"version": "4.0.0", | ||
"description": "Create performant HTML elements", | ||
@@ -9,3 +9,3 @@ "main": "index.js", | ||
"deps": "dependency-check . && dependency-check . --extra --no-dev -i yo-yoify", | ||
"start": "bankai example --open", | ||
"start": "bankai start example --optimize", | ||
"test": "standard && npm run deps", | ||
@@ -12,0 +12,0 @@ "test:cov": "standard && npm run deps" |
@@ -41,16 +41,52 @@ # nanocomponent [![stability][0]][1] | ||
## Implementing higher level APIs | ||
No matter the language, inheritance is tricky. Each layer adds more | ||
abstractions and can make it hard to understand what's going on. That's why we | ||
don't recommend doing more than one level of inheritance. However, this means | ||
that any API built on top of Nanocomponent directly shouldn't also expose a | ||
prototypical API. | ||
Instead we recommend people use an interface that somewhat resembles Node's | ||
`require('events').EventEmitter` API. | ||
```js | ||
var MyComponent = require('./my-component') | ||
var myComponent = MyComponent() | ||
myComponent.on('render', function () { | ||
console.log('rendered') | ||
}) | ||
myComponent.on('load', function () { | ||
console.log('loaded on DOM') | ||
}) | ||
myComponent.on('unload', function () { | ||
console.log('removed from DOM') | ||
}) | ||
document.body.appendChild(myComponent.render()) | ||
``` | ||
This API allows consumers of the `MyComponent` to hook into the event system | ||
without needing to inherit. It also allows `MyComponent` to expose more hooks | ||
with little cost. See | ||
[yoshuawuyts/microcomponent](https://github.com/yoshuawuyts/microcomponent) for | ||
an example of how to create a higher level interface. | ||
## API | ||
### `Nanocomponent.prototype()` | ||
Inheritable Nanocomponent prototype. Should be inherited from using | ||
`Nanococomponent.call(this)` and `prototype = Object.create(Nanocomponent.prototype)`. | ||
`Nanococomponent.call(this)` and `prototype = Object.create(Nanocomponent)`. | ||
Internal properties are: | ||
- __this._placeholder:__ placeholder element that's returned on subsequent | ||
- `this._placeholder`: placeholder element that's returned on subsequent | ||
`render()` calls that don't pass the `._update()` check. | ||
- __this._element:__ rendered element that should be returned from the first | ||
- `this._element`: rendered element that should be returned from the first | ||
`._render()` call. Used to apply `._load()` and `._unload()` listeners on. | ||
- __this._hasWindow:__ boolean if `window` exists. Can be used to create | ||
- `this._hasWindow`: boolean if `window` exists. Can be used to create | ||
elements that render both in the browser and in Node. | ||
- __this._loaded:__ boolean if the element is currently loaded on the DOM. | ||
- __this._onload:__ reference to the [on-load][on-load] library. | ||
- `this._loaded`: boolean if the element is currently loaded on the DOM. | ||
- `this._onload`: reference to the [on-load][on-load] library. | ||
@@ -67,9 +103,10 @@ ### `DOMNode|placeholder = Nanocomponent.prototype.render()` | ||
### `Nanocomponent.prototype._render([arguments])` | ||
Render an HTML node with arguments. For `prototype._load()` and | ||
`prototype._unload()` to work, make sure you return the same node on subsequent | ||
renders. The Node that's initially returned is saved as `this._element`. | ||
__Must be implemented.__ Render an HTML node with arguments. For | ||
`prototype._load()` and `prototype._unload()` to work, make sure you return the | ||
same node on subsequent renders. The Node that's initially returned is saved as | ||
`this._element`. | ||
### `Nanocomponent.prototype._update([arguments])` | ||
Return a boolean to determine if `prototype._render()` should be called. | ||
Evaluates to `true` if not implemented. Not called on the first render. | ||
__Must be implemented.__ Return a boolean to determine if `prototype._render()` | ||
should be called. Not called on the first render. | ||
@@ -88,12 +125,12 @@ ### `Nanocomponent.prototype._load()` | ||
## See Also | ||
- [bendrucker/document-ready](https://github.com/bendrucker/document-ready) | ||
- [shama/bel](https://github.com/shama/bel) | ||
- [shama/on-load](https://github.com/shama/on-load) | ||
- [yoshuawuyts/choo](https://github.com/yoshuawuyts/choo) | ||
- [yoshuawuyts/nanomorph](https://github.com/yoshuawuyts/nanomorph) | ||
- [yoshuawuyts/nanoraf](https://github.com/yoshuawuyts/nanoraf) | ||
- [yoshuawuyts/nanotick](https://github.com/yoshuawuyts/nanotick) | ||
- [shama/on-load](https://github.com/shama/on-load) | ||
- [yoshuawuyts/observe-resize](https://github.com/yoshuawuyts/observe-resize) | ||
- [bendrucker/document-ready](https://github.com/bendrucker/document-ready) | ||
- [yoshuawuyts/on-intersect](https://github.com/yoshuawuyts/on-intersect) | ||
- [yoshuawuyts/polite-element](https://github.com/yoshuawuyts/polite-element) | ||
- [yoshuawuyts/on-idle](https://github.com/yoshuawuyts/on-idle) | ||
- [yoshuawuyts/nanobounce](https://github.com/yoshuawuyts/nanobounce) | ||
- [yoshuawuyts/nanoframe](https://github.com/yoshuawuyts/nanoframe) | ||
@@ -103,2 +140,3 @@ ## Similar Packages | ||
- [yoshuawuyts/cache-element](https://github.com/yoshuawuyts/cache-element) | ||
- [yoshuawuyts/microcomponent](https://github.com/yoshuawuyts/microcomponent) | ||
@@ -105,0 +143,0 @@ ## License |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26798
157
748