开发者社区> 镜像站> NPM> nanomap
nanomap
Functionally map data into DOM component instances
Last updated 3 years ago by bret .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install nanomap 
SYNC missed versions from official npm registry.

nanomap stability

npm version build status downloads js-standard-style

Functionally map data into stateful nanocomponents.

Usage

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

Installation

$ npm install nanomap

API

Nanomap = require('nanomap)

Import Nanomap component class.

mapper = new Nanomap([opts], Component)

mapper = Nanomap([opts], { type: Component, [default: Component]})

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.

License

MIT

Current Tags

  • 1.1.1                                ...           latest (3 years ago)

3 Versions

  • 1.1.1                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (15)
Dependents (0)
None