conductor
Why I'm building conductorGitHub
v1.5.0
v1.5.0
  • Introduction
  • Overview
    • Introduction
    • Core concepts
  • API reference
    • always
    • append
    • apply
    • arity
    • branch
    • capitalize
    • compose
    • concat
    • curry
    • curryN
    • delay
    • dump
    • entries
    • equals
    • equalsBy
    • factory
    • filter
    • findIndex
    • flatten
    • flip
    • forEach
    • get
    • head
    • ifElse
    • identity
    • into
    • isPromise
    • iterate
    • join
    • keys
    • map
    • merge
    • mergeBy
    • next
    • not
    • pluck
    • prepend
    • random
    • reduce
    • replace
    • slice
    • some
    • split
    • take
    • then
    • toLowerCase
    • transduce
    • transformers
      • transformers/filter
      • transformers/map
    • type
    • upsert
    • values
  • Guides
    • example use cases
    • checkGuards
Powered by GitBook
On this page
  • description
  • examples
  • constant values
  • function values
  • nested specification
  1. API reference

factory

flatten :: Object specification => (Any, Any, ...) -> Object

description

Create a factory function using the provided specification object. The factory method has 2 magical powers:

  • the specification object can contain constant values, but also functions which will be called everytime the factory function is called (arguments will be passed as-is)

  • the specification object can be nested: factory works recursively.

examples

constant values

import { factory } from 'conductor'

const spec = { name: 'Elliot', type: 'hacker' }
const Hacker = factory(spec)
Hacker() // { name: 'Elliot', type: 'hacker' }

function values

import { factory } from 'conductor'

const spec = { name: x => x, createdAt: () => Date.now() }
const Hacker = factory(spec)
Hacker('Elliot') // { name: 'Elliot', createdAt: 1529249582304 }

nested specification

import { factory } from 'conductor'

const spec = {
  id: 1,
  name: x => x,
  metadata: {
    createdAt: () => Date.now(),
    type: 'hacker'
  }
const Hacker = factory(spec)
Hacker('Elliot')
// {
//   id: 1,
//   name: 'Elliot',
//   metadata: {
//     createdAt: 1529249582304,
//     type: 'hacker'
//   }
// }
PreviousequalsByNextfilter

Last updated 6 years ago