Merge branch 'updux-signature'

This commit is contained in:
Yanick Champoux 2019-10-29 11:35:13 -04:00
commit 122ff71260
16 changed files with 37 additions and 16 deletions

View File

@ -1,5 +1,9 @@
# Revision history for Updux # Revision history for Updux
NEXT
- point types to right file.
- add state to updux type.
0.2.0 2019-10-24 0.2.0 2019-10-24
- Converted everything to Typescript. - Converted everything to Typescript.

2
dist/buildMutations/test.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=test.d.ts.map

1
dist/buildMutations/test.d.ts.map vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../../src/buildMutations/test.ts"],"names":[],"mappings":""}

13
dist/buildMutations/test.js vendored Normal file
View File

@ -0,0 +1,13 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const _1 = __importDefault(require("."));
const actions = {
multiply: (factor) => ({ factor }),
};
const mutations = _1.default({
multiply: ({ factor }) => ({ counter }) => factor * counter,
});
//# sourceMappingURL=test.js.map

1
dist/buildMutations/test.js.map vendored Normal file
View File

@ -0,0 +1 @@
{"version":3,"file":"test.js","sourceRoot":"","sources":["../../src/buildMutations/test.ts"],"names":[],"mappings":";;;;;AAAA,yCAA+B;AAE/B,MAAM,OAAO,GAAG;IACZ,QAAQ,EAAE,CAAC,MAAc,EAAE,EAAE,CAAC,CAAC,EAAC,MAAM,EAAC,CAAC;CAC3C,CAAC;AAEF,MAAM,SAAS,GAAG,UAAc,CAC5B;IACI,QAAQ,EAAE,CAAC,EAAC,MAAM,EAAC,EAAE,EAAE,CAAC,CAAC,EAAC,OAAO,EAAC,EAAE,EAAE,CAAC,MAAM,GAAG,OAAO;CAC1D,CACJ,CAAC"}

View File

@ -2,7 +2,7 @@
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
function buildUpreducer(initial, mutations) { function buildUpreducer(initial, mutations) {
return (action) => (state) => { return (action) => (state) => {
if (state === null) if (state === undefined)
state = initial; state = initial;
const a = mutations[action.type] || const a = mutations[action.type] ||
mutations['*']; mutations['*'];

View File

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/buildUpreducer/index.ts"],"names":[],"mappings":";;AAIA,SAAS,cAAc,CAAI,OAAU,EAAE,SAAkC;IACvE,OAAO,CAAC,MAAc,EAAE,EAAE,CAAC,CAAC,KAAQ,EAAE,EAAE;QACtC,IAAI,KAAK,KAAK,IAAI;YAAE,KAAK,GAAG,OAAO,CAAC;QAEpC,MAAM,CAAC,GACL,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC;YACtB,SAAS,CAAC,GAAG,CAAC,CAAC;QAEjB,IAAG,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;QAEpB,OAAO,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC,CAAC;AACJ,CAAC;AAED,kBAAe,cAAc,CAAC"} {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/buildUpreducer/index.ts"],"names":[],"mappings":";;AAIA,SAAS,cAAc,CAAI,OAAU,EAAE,SAAkC;IACvE,OAAO,CAAC,MAAc,EAAE,EAAE,CAAC,CAAC,KAAQ,EAAE,EAAE;QACtC,IAAI,KAAK,KAAK,SAAS;YAAE,KAAK,GAAG,OAAO,CAAC;QAEzC,MAAM,CAAC,GACL,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC;YACtB,SAAS,CAAC,GAAG,CAAC,CAAC;QAEjB,IAAG,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;QAEpB,OAAO,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC,CAAC;AACJ,CAAC;AAED,kBAAe,cAAc,CAAC"}

2
dist/index.d.ts vendored
View File

@ -1,4 +1,4 @@
import Updux from './updux'; import Updux from './updux';
import { UpduxConfig } from './types'; import { UpduxConfig } from './types';
export default function updux(config: UpduxConfig): Updux<any>; export default function updux<S = any>(config: UpduxConfig<S>): Updux<S>;
//# sourceMappingURL=index.d.ts.map //# sourceMappingURL=index.d.ts.map

2
dist/index.d.ts.map vendored
View File

@ -1 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,SAAS,CAAC;AAE5B,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,MAAM,EAAE,WAAW,cAEhD"} {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,SAAS,CAAC;AAE5B,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,CAAC,GAAC,GAAG,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,YAE1D"}

2
dist/index.js.map vendored
View File

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAGA,oDAA4B;AAI5B,SAAwB,KAAK,CAAC,MAAmB;IAC/C,OAAO,IAAI,eAAK,CAAC,MAAM,CAAC,CAAC;AAC3B,CAAC;AAFD,wBAEC"} {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAGA,oDAA4B;AAI5B,SAAwB,KAAK,CAAQ,MAAsB;IACzD,OAAO,IAAI,eAAK,CAAI,MAAM,CAAC,CAAC;AAC9B,CAAC;AAFD,wBAEC"}

6
dist/test.js vendored
View File

@ -25,7 +25,7 @@ test('reducer', () => {
inc: () => ({ counter }) => ({ counter: counter + 1 }), inc: () => ({ counter }) => ({ counter: counter + 1 }),
}, },
}); });
let state = reducer(null, { type: 'noop' }); let state = reducer(undefined, { type: 'noop' });
expect(state).toEqual({ counter: 1 }); expect(state).toEqual({ counter: 1 });
state = reducer(state, actions.inc()); state = reducer(state, actions.inc());
expect(state).toEqual({ counter: 2 }); expect(state).toEqual({ counter: 2 });
@ -52,7 +52,7 @@ test('sub reducers', () => {
}); });
expect(initial).toEqual({ foo: 1, bar: 'a' }); expect(initial).toEqual({ foo: 1, bar: 'a' });
expect(Object.keys(actions)).toHaveLength(3); expect(Object.keys(actions)).toHaveLength(3);
let state = reducer(null, { type: 'noop' }); let state = reducer(undefined, { type: 'noop' });
expect(state).toEqual({ foo: 1, bar: 'a' }); expect(state).toEqual({ foo: 1, bar: 'a' });
state = reducer(state, actions.doFoo()); state = reducer(state, actions.doFoo());
expect(state).toEqual({ foo: 2, bar: 'a' }); expect(state).toEqual({ foo: 2, bar: 'a' });
@ -89,7 +89,7 @@ test('precedence between root and sub-reducers', () => {
expect(initial).toEqual({ expect(initial).toEqual({
foo: { bar: 4, quux: 3 } foo: { bar: 4, quux: 3 }
}); });
expect(reducer(null, actions.inc())).toEqual({ expect(reducer(undefined, actions.inc())).toEqual({
foo: { bar: 5, quux: 3 }, surprise: 5 foo: { bar: 5, quux: 3 }, surprise: 5
}); });
}); });

2
dist/test.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -38,5 +38,5 @@
"url": "https://github.com/yanick/updux/issues" "url": "https://github.com/yanick/updux/issues"
}, },
"homepage": "https://github.com/yanick/updux#readme", "homepage": "https://github.com/yanick/updux#readme",
"types": "./index.d.ts" "types": "./dist/index.d.ts"
} }

View File

@ -4,7 +4,7 @@ import { Dictionary, Mutation, Action, Upreducer } from '../types';
function buildUpreducer<S>(initial: S, mutations: Dictionary<Mutation<S>> ): Upreducer<S> { function buildUpreducer<S>(initial: S, mutations: Dictionary<Mutation<S>> ): Upreducer<S> {
return (action :Action) => (state: S) => { return (action :Action) => (state: S) => {
if (state === null) state = initial; if (state === undefined) state = initial;
const a = const a =
mutations[action.type] || mutations[action.type] ||

View File

@ -5,6 +5,6 @@ import Updux from './updux';
import { UpduxConfig } from './types'; import { UpduxConfig } from './types';
export default function updux(config: UpduxConfig) { export default function updux<S=any>(config: UpduxConfig<S>) {
return new Updux(config); return new Updux<S>(config);
} }

View File

@ -28,7 +28,7 @@ test('reducer', () => {
}, },
}); });
let state = reducer(null, {type:'noop'}); let state = reducer(undefined, {type:'noop'});
expect(state).toEqual({counter: 1}); expect(state).toEqual({counter: 1});
@ -64,7 +64,7 @@ test( 'sub reducers', () => {
expect(Object.keys(actions)).toHaveLength(3); expect(Object.keys(actions)).toHaveLength(3);
let state = reducer(null,{type:'noop'}); let state = reducer(undefined,{type:'noop'});
expect(state).toEqual({ foo: 1, bar: 'a' }); expect(state).toEqual({ foo: 1, bar: 'a' });
@ -116,7 +116,7 @@ test('precedence between root and sub-reducers', () => {
foo: { bar: 4, quux: 3 } foo: { bar: 4, quux: 3 }
}); });
expect( reducer(null,actions.inc() ) ).toEqual({ expect( reducer(undefined,actions.inc() ) ).toEqual({
foo: { bar: 5, quux: 3 }, surprise: 5 foo: { bar: 5, quux: 3 }, surprise: 5
}); });