Mate.js - Front Controller library following Flux Pattern
Last updated a year ago by nirth .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install matejs 
SYNC missed versions from official npm registry.



This is not a real library, instead this is an exploration of how to improve my work with Redux and React Redux, please don't use this in production.

The reason I'm playing around with this library is because I think that metaphor or a Reducer is not close enough, we are not reducing our state, we are mapping over it. This library explores this idea.

Consider following example:

// Selector, in real life we would memoize it
const selectSum = (state) => state.sum;
// Creating simple event with type and payload
const createAddEvent = (summand) => ({type: 'add', payload: summand})

// Mapper takes in values and returns new values.
// I know, at this point it actually looks exactly like reducing,
const mapSum = (event, state) => {
  const sum = selectSum(state)
  return sum + event.payload

// Define initial state
const initialState = {sum: 0}

// And here it get's interesting, define eventMap
// EventMap will tell which mapper should be triggered for specific field
const eventMap = [['sum', allowEventType('add'), mapSum]]

// In example above, every time we get event `add`,
//function `mapSum` will be used to map new value to `sum`.

// Standard - create store
const store = createStore(eventMap, initialState)


console.log(`Sum is ${store.state.sum}`) // Sum is 6

Concepts and How Tos


Signature: Event = {type: string, payload: ?Object} Event is a special type of object, that triggers a behavior. It consists of two main parameters: type that describes it, and payload that contains data needed to process event.

Transformers and EventHandlers

type Transformer = (event: Event, state: State, subState: SubState) => SubState

Event handler is a function that takes in three arguments: event, entire state, and it's subState, and returns new value for it‘s subState.

Architecture Decisions

Explicit "curried" function, instead of auto-curry.

Explicitly defined curried function (e.g. (a, b) => (c) => a + b + c) was favoured in long run due to performance concerns, even if curry provided by Ramda or Lodash is much prettier and cleaner solution.

Current Tags

  • 0.4.1                                ...           latest (a year ago)

10 Versions

  • 0.4.1                                ...           a year ago
  • 0.4.0                                ...           a year ago
  • 0.3.4                                ...           a year ago
  • 0.3.3                                ...           a year ago
  • 0.3.2                                ...           a year ago
  • 0.3.1                                ...           a year ago
  • 0.3.0                                ...           a year ago
  • 0.2.0                                ...           a year ago
  • 0.1.6                                ...           2 years ago
  • 0.1.4                                ...           2 years ago
Maintainers (1)
Today 0
This Week 1
This Month 3
Last Day 0
Last Week 2
Last Month 4
Dependencies (2)
Dev Dependencies (18)
Dependents (0)

Copyright 2014 - 2016 © |