Skip to content

Commit bfbd637

Browse files
committed
export type from react-most.ts
1 parent 60416e6 commit bfbd637

File tree

5 files changed

+35
-18
lines changed

5 files changed

+35
-18
lines changed

lib/__tests__/react-most-test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import ReactDOM from 'react-dom';
33
import TestUtils from 'react-addons-test-utils';
44
import * as most from 'most';
55

6-
import Most, {connect} from '../react-most';
6+
import Most, {connect} from '../../dist/react-most';
77
import {stateStreamOf, stateHistoryOf,
88
intentStreamOf, intentHistoryOf,
99
run, dispatch,

lib/react-most.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import PropTypes from 'prop-types';
2+
import { PropTypes } from 'prop-types';
33
import initHistory, { Traveler } from './history';
44
import { from, Stream, Subscription } from 'most';
55
import { Engine, EngineSubject } from './engine/most';
@@ -10,30 +10,37 @@ const CONTEXT_TYPE = {
1010
[REACT_MOST_ENGINE]: PropTypes.object
1111
};
1212

13-
interface Actions<T> {
13+
export interface Actions<T> {
1414
[propName: string]: (...v: any[]) => T
1515
}
1616

17-
interface Plan<I, S> {
18-
(intent: EngineSubject<I>, props?: {}): Process<I,S>
17+
export interface Plan<I, S> {
18+
(intent: EngineSubject<I>, props?: {}): Process<I, S>
1919
}
20-
interface Update<S> {
20+
export interface Update<S> {
2121
(current: S): S
2222
}
23-
interface Process<I,S> {
23+
export interface Process<I, S> {
2424
actions: Actions<I>,
2525
updates: Stream<Update<S>>
2626
}
2727

28-
interface ConnectProps<I> {
28+
export interface ConnectProps<I> {
2929
actions: Actions<I>
3030
}
3131
const h = React.createElement;
32-
function connect<I,S>(main: Plan<I,S>, opts = { history: false }) {
32+
export class Connect<I, S> extends React.PureComponent<ConnectProps<I>, S> {
33+
actions: Actions<I>
34+
updates: Stream<Update<S>>
35+
}
36+
export interface ConnectClass<I, S> {
37+
new (props?: ConnectProps<I>, context?: any): Connect<I, S>;
38+
}
39+
export function connect<I, S>(main: Plan<I, S>, opts = { history: false }): (WrappedComponent: React.ComponentClass<any>) => ConnectClass<I, S> {
3340
return function(WrappedComponent: React.ComponentClass<any>) {
3441
let connectDisplayName = `Connect(${getDisplayName(WrappedComponent)})`;
3542
if (WrappedComponent.contextTypes === CONTEXT_TYPE) {
36-
return class ConnectNode extends React.PureComponent<ConnectProps<I>, any>{
43+
return class ConnectNode extends Connect<I, S>{
3744
actions: Actions<I>
3845
updates: Stream<Update<S>>
3946
static contextTypes = CONTEXT_TYPE
@@ -55,7 +62,7 @@ function connect<I,S>(main: Plan<I,S>, opts = { history: false }) {
5562
}
5663
}
5764
} else {
58-
return class ConnectLeaf extends React.PureComponent<ConnectProps<I>, S> {
65+
return class ConnectLeaf extends Connect<I, S> {
5966
actions: Actions<I>
6067
updates: Stream<Update<S>>
6168
traveler: Traveler<S>
@@ -71,7 +78,7 @@ function connect<I,S>(main: Plan<I,S>, opts = { history: false }) {
7178
}
7279

7380
let { actions, updates } = main(context[REACT_MOST_ENGINE].engine.intentStream, props)
74-
this.updates = props.updates?updates.merge(props.updates) : updates
81+
this.updates = props.updates ? updates.merge(props.updates) : updates
7582
this.actions = Object.assign({}, actions, props.actions);
7683
let defaultKey = Object.keys(WrappedComponent.defaultProps);
7784
this.state = Object.assign(

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
],
1919
"scripts": {
2020
"license": "(cat LICENSE.txt; cat react-most.js) > react-most.licensed.js && mv react-most.licensed.js react-most.js",
21-
"build": "babel lib -d ./ --ignore '__tests__' && npm run license",
21+
"build": "tsc -p .",
2222
"prebrowser": "npm run build",
2323
"browser": "browserify -r react -r most -r most-subject -o dist/vendor.js && browserify -s Most -x react -x most -x most-subject react-most.js -o dist/react-most.js",
2424
"test": "jest --coverage",
@@ -35,6 +35,7 @@
3535
"react": "^15.5.4"
3636
},
3737
"devDependencies": {
38+
"@types/node": "^7.0.18",
3839
"@types/react": "^15.0.22",
3940
"babel": "^6.1.18",
4041
"babel-cli": "^6.2.0",
@@ -49,7 +50,8 @@
4950
"react-addons-test-utils": "^15.2.0",
5051
"react-dom": "^15.5.4",
5152
"react-most-spec": "^0.2.3",
52-
"redux": "^3.0.4"
53+
"redux": "^3.0.4",
54+
"typescript": "^2.3.2"
5355
},
5456
"jest": {
5557
"moduleFileExtensions": [

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
],
55
"compilerOptions": {
66
"module": "commonjs",
7-
"lib": ["es2015", "dom", "node"],
7+
"lib": ["es2015","dom"],
88
"target": "es5",
99
"outDir": "dist",
1010
"declarationDir": "types",

yarn.lock

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@
1212
version "1.4.1"
1313
resolved "https://registry.yarnpkg.com/@most/prelude/-/prelude-1.4.1.tgz#b940b5563096f27637401618a5351f42466ea8f3"
1414

15-
"@types/react@^15.0.23":
16-
version "15.0.23"
17-
resolved "https://registry.yarnpkg.com/@types/react/-/react-15.0.23.tgz#f3facbef5290610f54242f00308759d3a3c27346"
15+
"@types/node@^7.0.18":
16+
version "7.0.18"
17+
resolved "https://registry.yarnpkg.com/@types/node/-/node-7.0.18.tgz#cd67f27d3dc0cfb746f0bdd5e086c4c5d55be173"
18+
19+
"@types/react@^15.0.22":
20+
version "15.0.24"
21+
resolved "https://registry.yarnpkg.com/@types/react/-/react-15.0.24.tgz#8a75299dc37906df327c18ca918bf97a55e7123b"
1822

1923
abab@^1.0.3:
2024
version "1.0.3"
@@ -3026,6 +3030,10 @@ type-check@~0.3.2:
30263030
dependencies:
30273031
prelude-ls "~1.1.2"
30283032

3033+
typescript@^2.3.2:
3034+
version "2.3.2"
3035+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.3.2.tgz#f0f045e196f69a72f06b25fd3bd39d01c3ce9984"
3036+
30293037
ua-parser-js@^0.7.9:
30303038
version "0.7.12"
30313039
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.12.tgz#04c81a99bdd5dc52263ea29d24c6bf8d4818a4bb"

0 commit comments

Comments
 (0)