@sidefx/core

0.3.0 • Public • Published

TODO




npm install @sidefx/core --save
https://unpkg.com/@sidefx/core


// SideFx is a minimal interface to make development 
// with purely functional code easier and testable

import {fx, inject} from '@sidefx/core'

// declare custom effects.
// must returns a function
const mySideEffect = (value) => {
  const effect = () => {
    global.crazySideEffects(value)
    console.log(`Hello ${value}`)
  }
  effect.value = value
  return effect
}

// define injections, DRY
inject({ myState: '!'  })

// then code with pure functions.
// injections passed as first parameter
const myFunction = fx(({ myState }, value) => {
  return [ mySideEffect(value + myState) ]
})

// get returned values without
// executing the side effects
console.log(myFunction.pure('Mars'))
// -> [function effect()]
console.log(myFunction.pure('Mars')[0].value)
// -> 'Mars!'

// or just run the function
// to execute the side effects
myFunction('Earth')
// -> 'Hello Earth!'

/@sidefx/core/

    Package Sidebar

    Install

    npm i @sidefx/core

    Weekly Downloads

    6

    Version

    0.3.0

    License

    MIT

    Last publish

    Collaborators

    • sidefx