ds300 / derivablejs

Functional Reactive State for JavaScript and TypeScript
Apache License 2.0
515 stars 23 forks source link

Example code not work #118

Closed sphynx79 closed 6 years ago

sphynx79 commented 6 years ago

Hi,

i try to use this simple code in derivable 2.0.0-beta.3, i take this code from documentation

import { derive, atom, setDebugMode } from "derivable"
setDebugMode(true)

const x = atom(4)
const times = (a, b) => a * b
const xTimesTwo = x.derive(times, 2)

console.log(xTimesTwo.get())

but result is NaN

until version 2.0.0-beta.1 this code work fine

TrySound commented 6 years ago

Additional arguments support was removed. Use function scope instead. https://github.com/ds300/derivablejs/commit/371012e9e12358fb6ee936a0b287b6ff8689868f

sphynx79 commented 6 years ago
const x = atom(4);
const times = (a, b) => a * b;
const xTimesTwo = x.derive((x)=> times(x,2));

in this way

TrySound commented 6 years ago

Yep, this way.

sphynx79 commented 6 years ago

also if i preferer old way!!

Thanks.

TrySound commented 6 years ago

Docs is a bad side of this project. If you would like to help with it I'm open for questions.