0.9.1 • Published 6 years ago

object-functional v0.9.1

Weekly downloads
6
License
BSD-2-Clause
Repository
github
Last release
6 years ago

js-object-functional

Object-Functional programming paradigm for JavaScript, including change isolation, observables, and frozen views.

Class-based Example

import {ObjectFunctional} from 'object-functional'

class CounterWithList extends ObjectFunctional ::
  asAction = this.init
  init(counter=0) ::
    this.counter = counter
    this.lst = Object.freeze @ @[] counter
    return this

  asAction = this.increment
  increment(howHigh=1) ::
    this.counter += howHigh
    this.lst = Object.freeze @ this.lst.concat @ this.counter
    return this

  asAction = this.decrement
  decrement(howLow=1) ::
    this.counter -= howLow
    this.lst = Object.freeze @ this.lst.concat @ this.counter
    return this

  last() ::
    return this.lst[this.lst.length - 1]


// ...

const obj = new CounterWithList().init()
obj.subscribe @ view =>
  console.log('Update:', {view})

setInterval @
  () => obj.increment()
  1000

Prototype-based Example

import {asFunctionalProto} from 'object-functional'

const createCounterWithList = asFunctionalProto @:
  counter: 0
  lst: Object.freeze @ []

  asAction: @{}
    increment(howHigh=1) ::
      this.counter += howHigh
      this.lst = Object.freeze @ this.lst.concat @ this.counter
      return this

    decrement(howLow=1) ::
      this.counter -= howLow
      this.lst = Object.freeze @ this.lst.concat @ this.counter
      return this

  last() ::
    return this.lst[this.lst.length - 1]



// ...

const obj = createCounterWithList()
obj.subscribe @ view =>
  console.log('Update:', {view})

setInterval @
  () => obj.increment()
  1000
0.9.1

6 years ago

0.9.0

6 years ago

0.8.0

6 years ago

0.7.1

6 years ago

0.7.0

6 years ago

0.6.0

6 years ago

0.5.0

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago

0.0.0

7 years ago