[@types/nuclear-js] Make sure interfaces are exported (#40386)

* Make sure interfaces are exported

* Fix some lint warnings
This commit is contained in:
Pat Lillis
2019-11-14 16:08:26 -08:00
committed by Pranav Senthilnathan
parent 415e680187
commit c8287ed1e7
2 changed files with 66 additions and 16 deletions
+20 -7
View File
@@ -2,7 +2,6 @@
// Project: https://github.com/optimizely/nuclear-js
// Definitions by: Pat Lillis <https://github.com/patlillis>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import * as _Immutable from 'immutable';
@@ -27,7 +26,15 @@ interface ReactMixin {
componentWillUnmount(): void;
}
interface Reactor {
/**
* State is stored in NuclearJS Reactors. Reactors contain a `state` object
* which is an Immutable.Map
*
* The only way Reactors can change state is by reacting to messages. To
* update state, Reactor's dispatch messages to all registered stores, and
* the store returns it's new state based on the message
*/
export interface Reactor {
prevReactorState: any;
reactorState: any;
observerState: any;
@@ -102,7 +109,7 @@ interface Reactor {
/**
* Registers stores.
*/
registerStores(stores: { [storeName: string]: Store<any> }): void;
registerStores(stores: { [storeName: string]: Store }): void;
/**
* Replace store implementation (handlers) without modifying the app
@@ -110,7 +117,7 @@ interface Reactor {
*
* Useful for hot reloading
*/
replaceStores(stores: { [storeName: string]: Store<any> }): void;
replaceStores(stores: { [storeName: string]: Store }): void;
/**
* Resets the state of a reactor and returns it back to initial state.
@@ -140,7 +147,13 @@ export const Reactor: {
(config?: ReactorConfig): Reactor;
};
interface Store<T> extends StoreLike<T> {
/**
* A Store defines how a certain domain of the application should respond to
* actions taken on the whole system. They manage their own section of the
* entire app state and have no knowledge about the other parts of the
* application state.
*/
export interface Store<T = any> extends StoreLike<T> {
/**
* Takes a current reactor state, action type and payload, does the
* reaction, and returns the new state.
@@ -219,7 +232,7 @@ export const Store: {
* entire app state and have no knowledge about the other parts of the
* application state.
*/
new <T = any>(config: StoreLike<T>): Store<T>;
new <T>(config: StoreLike<T>): Store<T>;
/**
* A Store defines how a certain domain of the application should respond to
@@ -227,7 +240,7 @@ export const Store: {
* entire app state and have no knowledge about the other parts of the
* application state.
*/
<T = any>(config: StoreLike<T>): Store<T>;
<T>(config: StoreLike<T>): Store<T>;
};
/**
+46 -9
View File
@@ -19,8 +19,8 @@ Reactor();
new Reactor({ debug: true });
Reactor({ debug: undefined });
// Make sure that type checking succeeds with or without `new`.
const r1 = new Reactor();
const r2 = Reactor();
const r1: Reactor = new Reactor();
const r2: Reactor = Reactor();
r1.dispatch('FETCH_ENTITY_SUCCESS');
r1.dispatch('FETCH_ENTITY_SUCCESS', { data: 5 });
r1.batch(() => null);
@@ -101,12 +101,32 @@ r2.ReactMixin.componentWillUnmount();
r2.ReactMixin.getInitialState();
// Callable with or without `new`.
new Store({ getInitialState() {}, initialize() {} });
Store({ getInitialState() {}, initialize() {} });
new Store({ getInitialState() {}, initialize() {} });
Store({ getInitialState() {}, initialize() {} });
new Store({
getInitialState() {
return {};
},
initialize() {},
});
Store({
getInitialState() {
return {};
},
initialize() {},
});
new Store({
getInitialState() {
return {};
},
initialize() {},
});
Store({
getInitialState() {
return {};
},
initialize() {},
});
// Make sure that type checking succeeds with or without `new`.
const s1 = new Store<number>({
const s1: Store<number> = new Store<number>({
getInitialState() {
return 5;
},
@@ -114,7 +134,7 @@ const s1 = new Store<number>({
this.on('FETCH_THING', (s: number, x: any) => 5);
},
});
const s2 = Store<string>({
const s2: Store<string> = Store<string>({
getInitialState() {
return '';
},
@@ -125,6 +145,18 @@ const s2 = Store<string>({
return '15';
},
});
const s3: Store = new Store({
getInitialState() {
return {};
},
initialize() {},
});
const s4: Store = Store({
getInitialState() {
return {};
},
initialize() {},
});
s1.getInitialState();
s1.initialize();
s1.handleReset(5);
@@ -172,7 +204,12 @@ createReactMixin(r2);
import Nuclear = require('nuclear-js');
Nuclear.Immutable.Map({ a: 1 });
Nuclear.Reactor({ debug: true });
Nuclear.Store({ getInitialState() {}, initialize() {} });
Nuclear.Store({
getInitialState() {
return {};
},
initialize() {},
});
Nuclear.isKeyPath({});
Nuclear.isGetter({});
Nuclear.toJS({});