Skip to content

Latest commit

 

History

History
197 lines (144 loc) · 6.77 KB

README.md

File metadata and controls

197 lines (144 loc) · 6.77 KB

Modules

BazComponent

Interface of component, required by Bazooka.refresh

BazookaBazookaWrapper

Bazooka

Typedefs

HMRStateCallbackObject

Callback to get state between Webpack's hot module reloads (HMR)

BazComponent

Interface of component, required by Bazooka.refresh

BazComponent~simple ⇒ function

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) {}

BazComponent~universal

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.register(componentsObj)

Register components names

Kind: static method of Bazooka

Param Type Description
componentsObj Object object with names as keys and components as values

Bazooka.refresh([rootNode])

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

Bazooka.rebind(componentsObj)

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') }));
  }

Bazooka.watch([rootNode]) ⇒ function

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

Bazooka~BazookaWrapper

Reference to BazookaWrapper class

Kind: inner property of Bazooka

HMRStateCallback ⇒ Object

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

~BazookaWrapper

Kind: inner class

bazookaWrapper.getComponents() ⇒ Object.<string, BazComponent>

Kind: instance method of BazookaWrapper
Returns: Object.<string, BazComponent> - object of the bound to the wrapped node BazComponents

bazookaWrapper.HMRState(moduleHot, stateCallback) ⇒ Object

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();