- BazComponent
Interface of component, required by Bazooka.refresh
- Bazooka ⇒
BazookaWrapper
Bazooka
- HMRStateCallback ⇒
Object
Callback to get state between Webpack's hot module reloads (HMR)
Interface of component, required by Bazooka.refresh
- BazComponent
- ~simple ⇒
function
- ~universal
- ~simple ⇒
CommonJS module written only with Bazooka interface to be used with data-bazooka
Kind: inner interface of BazComponent
Returns: function
- dispose
callback to cleanup component's eventListeners
, timers, etc. after Bazooka.rebind or removal of the node from DOM
Type | Description |
---|---|
node |
bound DOM node |
Example
module.exports = function bazFunc(node) {}
CommonJS module with Bazooka interface, so it can be used both in data-bazooka
and in another CommonJS modules via require()
Kind: inner interface of BazComponent
Example
function trackEvent(category, action, label) {}
module.exports = {
bazFunc: function bazFunc(node) { node.onclick = trackEvent.bind(…) },
trackEvent: trackEvent,
}
Bazooka ⇒ BazookaWrapper
Bazooka
Param | Type | Description |
---|---|---|
value | node | BazookaWrapper |
DOM node or wrapped node |
Example
var Baz = require('bazooka');
var $baz = Baz(node);
- Bazooka ⇒
BazookaWrapper
- static
- inner
Register components names
Kind: static method of Bazooka
Param | Type | Description |
---|---|---|
componentsObj | Object |
object with names as keys and components as values |
Parse and bind bazooka components to nodes without bound components
Kind: static method of Bazooka
Param | Type | Default | Description |
---|---|---|---|
[rootNode] | node |
document.body |
DOM node, children of which will be checked for data-bazooka |
Rebind existing components. Nodes with already bound component will be disposed and bound again to a new bazFunc
Kind: static method of Bazooka
Param | Type | Description |
---|---|---|
componentsObj | Object |
object with new components |
Example
import bazFunc from './bazFunc.js'
Baz.register({
bazFunc: bazFunc,
});
Baz.watch();
if (module.hot) {
module.hot.accept('./bazFunc.js', () => Baz.rebind({ bazFunc: bazFunc }));
// or, if you prefer `require()`
// module.hot.accept('./bazFunc.js', () => Baz.rebind({ bazFunc: require('./bazFunc.js') }));
}
Watch for new nodes with data-bazooka
. No need to run Bazooka.refresh before this. It will be called automatically.
Kind: static method of Bazooka
Returns: function
- Unwatch function
Param | Type | Default | Description |
---|---|---|---|
[rootNode] | node |
document.body |
DOM node, children of which will be watched for data-bazooka |
Reference to BazookaWrapper class
Kind: inner property of Bazooka
Callback to get state between Webpack's hot module reloads (HMR)
Kind: global typedef
Returns: Object
- whatever state should be after HMR
Param | Type | Description |
---|---|---|
previous | Object |
state. undefined on first call |
Kind: inner class
- ~BazookaWrapper
- .getComponents() ⇒
Object.<string, BazComponent>
- .HMRState(moduleHot, stateCallback) ⇒
Object
- .getComponents() ⇒
Kind: instance method of BazookaWrapper
Returns: Object.<string, BazComponent>
- object of the bound to the wrapped node BazComponents
Helper method to preserve component's state between Webpack's hot module reloads (HMR)
Kind: instance method of BazookaWrapper
Returns: Object
- value from stateCallback
Param | Type | Description |
---|---|---|
moduleHot | webpackHotModule |
module.hot of the component |
stateCallback | HMRStateCallback |
callback to create state. Called with undefined prev on initial binding and with prev equal latest component state after every HMR |
Example
const state = module.hot
? Baz(node).HMRState(module.hot, prev => prev || model())
: model();