Giter Club home page Giter Club logo

jackalope's Introduction

Jackalope

A modular and microscopic SAM-patterned container
It draws inspiration from redux

Installation

npm install --save @jackalope/core

Usage

Jackalope adheres to the SAM pattern, which can be summarized by the formula:
V = S(vm(M.present(A(M))), nap(M, A)) (source)

You can read about SAM here: http://sam.js.org/

// src/jack.js
import Jackalope from '@jackalope/core'

import state from './state'
import actions from './actions'
import model from './model'

const J = Jackalope({ state, actions, model }/*, middleware */)

State

In Jackalope, state is a function that receives model as its first parameter. If the function does not specify arguments, or specifies more than 1, it will also receive actions bound automatically during instatiation as the second parameter.

Example:

// src/state.js
const state = (model, actions) => {
  const representation = 'Oops, you\'ve stumbled upon an impossible state'

  if (model.count > 0) {
    representation = view.counting(model, actions)
  } else if (model.count < 1) {
    representation = view.launching(model, actions)
  }

  ...

  view.render(representation)
  nap(model, actions)
}

export default state

Model

model is an object which contains your data. It must have a method, model.present which can either accept an action and update itself, or reject actions outright.
model.present is assumed to have curried form state => action => { ... }.

IMPORTANT : model.present is the only function allowed to mutate model in the SAM pattern.

Example:

// src/model.js
const model = {
  count: 10,
  ...
}

model.present = (state) => (action) => {
  if (action.started) {
    model.started = true
  }

  if (action.aborted) {
    model.aborted = true
  }

  ...
  
  state(model)
}

export default model

Actions

actions should be a function which accepts present (as in, model.present) as its only parameter.
It should return an object with functions that present proposals to the model.

// src/actions.js
const actions = present => ({
  start: function () {
    present({ started: true })
  },

  abort: function () {
    present({ aborted: true })
  },

  ...

})

export default actions

Jackalope Core

https://github.com/schtauffen/jackalope/tree/master/core

Extending Jackalope

TODO - more information coming

Composability

SAM apps are meant to be composable.
TODO - More to come

Disclaimer

Jackalope has been created mostly to learn about and play with the SAM pattern.
As is, there are no tests or plans for long term support. This may change pending on how useful this implementation is :)

License

Jackalope is licensed under the ISC license

jackalope's People

Contributors

schtauffen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.