Functionally map data into stateful nanocomponents.
var Nanomap = require('nanocomponent/map')
var YoutubeComponent = require('youtube-component')
var TwitterComponent = require('twitter-component')
var OEmbedComponent = require('oembed-component')
var simpleMapper = new Nanomap(opts, TwitterComponent)
// OR
var complexMapper = new Nanomap(opts, {
'video': YoutubeComponent,
'tweet': TwitterComponent,
...,
default: OEmbedComponent
})
[{
id: 'foo123',
opts: { color: 'blue' },
arguments: {an: 'arg'} // Non-array types passed in as the first argument
}].map(simpleMapper) // Array of rendered DOM nodes from homogeneous components
[{
id: 'foo123',
type: 'tweet',
arguments: ['tweet-url'] // component.render.apply(component, arguments)
}].map(complexMapper) // Array of rendered DOM nodes from a heterogeneous set of components
$ npm install nanomap
Import Nanomap
component class.
Create a new mapper instance that will render data into component instances.
opts
include:
{
gc: true // clean up unused instances when mapped over
}
See examples for more details.