Coder Social home page Coder Social logo

heineiuo / lois Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 152 KB

:girl: :book: Functional, predictable web framework for node.js

Home Page: https://heineiuo.github.io/lois

License: MIT License

JavaScript 92.60% Makefile 4.74% Shell 2.67%
actioncreator bindactioncreators

lois's Introduction

lois

Inspired by redux, lois a web framework to write predictable state data-flow web service.


中文文档

Get started

install

$ npm install lois

Example

const morgan = require('morgan')
const express = require('express')
const lois = require('lois')

const lex = lois.express
const symbols = lois.symbols

class User {
  reducer(state, action) {
    return state
  }

  _next(query) {
    return async (dispatch, getState) => {
      return symbols.NextSymbol
    }
  }

  _get(query) {
    return async (dispatch, getState) => {
      return {
        query: query
      }
    }
  }

  _ignore(query) {
    return async (dispatch, getState) => {
      const { response: res } = getState()
      res.write(JSON.stringify({ ignore: query }))
      res.end()
      return symbols.IgnoreSymbol
    }
  }
}


const user = new User()

const app = express()

app.use(morgan('dev'))
app.use(lex.createStore())
app.use('/user', lex.register('user', user))
app.use('/user/:userId', ...lex.transform(user._next))
app.get('/user/:userId', ...lex.transform(user._get))
app.get('/user/:userId/ignore', ...lex.transform(user._ignore, user._get))

app.listen(10723, () => console.log('running on port 10723'))

Documents

lois.express.createStore

lois.express.transform

lois.express.register

lois.symbols.NextSymbol

lois.symbols.IgnoreSymbol

License

MIT

lois's People

Contributors

heineiuo avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

tianjiantnt2

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.