0.2.0 • Published 10 years ago

cerebral-module-fuse v0.2.0

Weekly downloads
3
License
MIT
Repository
github
Last release
10 years ago

cerebral-module-fuse

A cerebral module that adds fuzzy search to data in the store.

Install

npm install cerebral-module-fuse

Usage

From your main.js

import controller from './controller'
import fuse from 'cerebral-module-fuse'

controller.modules({
  findUsers: fuse({
    statePath: 'users',  // statePath should point to either an object or array in the store
    options: { keys: ['firstName', 'lastName'] } // options are passed on to fuse.js
  })
})

See fuse docs for more information about available options.

from your component.js

import React from 'react'
import { connect } from 'cerebral-view-react'
import fuse from 'cerebral-module-fuse/computed'

export default connect({
  users: fuse({ modulePath: 'findUsers', statePath: 'users' })
}, ({ users }) => (
  <ul>
    {users.map(user => (
      <li>{`${user.firstName} ${user.lastName}`}</li>
    ))}
  </ul>
))

to execute the search simply call the search signal and the view will automatically update

signals.findUsers.search({ query: 'John' })

you can also access the filtered data from an action via the provided service

export default myAction({ state, services: { findUsers } }) {
  const users = findUsers.get(state)
}

Contribute

Fork repo

  • npm install
  • npm start runs dev mode which watches for changes and auto lints, tests and builds
  • npm test runs the tests
  • npm run lint lints the code
  • npm run build compiles es2015 to es5
0.2.0

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago