Skip to content

Commit

Permalink
Remove map and mMap functions
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound committed Nov 14, 2017
1 parent f6fe2d4 commit 6117436
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 71 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Expand Up @@ -9,7 +9,7 @@ import * as parents from './parents';
import {deepUnpack, unpack} from './unpack';

export {isDerivable, isAtom, isProxy, isDerivation} from './types';
export {map, mMap, or, mOr, and, mAnd} from './combinators.js';
export {or, mOr, and, mAnd} from './combinators.js';
export {transact, transaction, ticker, atomic, atomically} from './transactions';
export {Reactor as __Reactor} from './reactors';

Expand Down
100 changes: 30 additions & 70 deletions test/combinators_test.js
Expand Up @@ -3,79 +3,39 @@
const derivable = require('../dist/derivable');

test('map derivable value with function', () => {
{
const a = derivable.atom(1);
const q = derivable.atom(10);
const b = derivable.map(d => d + q.get(), a);
const c = derivable.map(d => d * q.get(), b);
expect([b.get(), c.get()]).toEqual([11, 110]);

q.set(20);
expect([b.get(), c.get()]).toEqual([21, 420]);

a.set(null);
expect([b.get(), c.get()]).toEqual([20, 400]);

expect(() => {
derivable.atom().map();
}).toThrow();
}

{
const a = derivable.atom(1);
const q = derivable.atom(10);
const b = a.map(d => d + q.get());
const c = b.map(d => d * q.get());
expect([b.get(), c.get()]).toEqual([11, 110]);

q.set(20);
expect([b.get(), c.get()]).toEqual([21, 420]);

a.set(null);
expect([b.get(), c.get()]).toEqual([20, 400]);

expect(() => {
derivable.map();
}).toThrow();
}
const a = derivable.atom(1);
const q = derivable.atom(10);
const b = a.map(d => d + q.get());
const c = b.map(d => d * q.get());
expect([b.get(), c.get()]).toEqual([11, 110]);

q.set(20);
expect([b.get(), c.get()]).toEqual([21, 420]);

a.set(null);
expect([b.get(), c.get()]).toEqual([20, 400]);

expect(() => {
derivable.map();
}).toThrow();
});

test('maybe map derivable (non-null) value with function', () => {
{
const a = derivable.atom(1);
const q = derivable.atom(10);
const b = derivable.mMap(d => d + q.get(), a);
const c = derivable.mMap(d => d * q.get(), b);
expect([b.get(), c.get()]).toEqual([11, 110]);

q.set(20);
expect([b.get(), c.get()]).toEqual([21, 420]);

a.set(null);
expect([b.get(), c.get()]).toEqual([null, null]);

expect(() => {
derivable.atom().map();
}).toThrow();
}

{
const a = derivable.atom(1);
const q = derivable.atom(10);
const b = a.mMap(d => d + q.get());
const c = b.mMap(d => d * q.get());
expect([b.get(), c.get()]).toEqual([11, 110]);

q.set(20);
expect([b.get(), c.get()]).toEqual([21, 420]);

a.set(null);
expect([b.get(), c.get()]).toEqual([null, null]);

expect(() => {
derivable.map();
}).toThrow();
}
const a = derivable.atom(1);
const q = derivable.atom(10);
const b = a.mMap(d => d + q.get());
const c = b.mMap(d => d * q.get());
expect([b.get(), c.get()]).toEqual([11, 110]);

q.set(20);
expect([b.get(), c.get()]).toEqual([21, 420]);

a.set(null);
expect([b.get(), c.get()]).toEqual([null, null]);

expect(() => {
derivable.map();
}).toThrow();
});

test('alt', () => {
Expand Down

0 comments on commit 6117436

Please sign in to comment.