Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

Commit

Permalink
resolves #88
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Stover committed Jun 4, 2019
1 parent 16d6c66 commit 0d1d9f0
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ module.exports = {
'warn', 2, {
SwitchCase: 1,
} ],
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-unused-vars': [
'error', {
args: 'all',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reactn",
"version": "2.1.1",
"version": "2.1.2",
"author": "Charles Stover <[email protected]>",
"description": "React, but with built-in global state management.",
"homepage": "https://github.com/CharlesStover/reactn#readme",
Expand Down
45 changes: 33 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React = require('react');
import { Reducers, State } from '../default';
import Callback from '../types/callback';
import {
Expand All @@ -8,6 +7,7 @@ import {
import Dispatcher, { ExtractArguments } from '../types/dispatcher';
import Dispatchers from '../types/dispatchers';
import NewGlobalState from '../types/new-global-state';
import Omit from '../types/omit';
import ReactNProvider from '../types/provider';
import Reducer, { AdditionalReducers } from '../types/reducer';
import { GlobalTuple, StateTuple } from '../types/use-global';
Expand All @@ -27,12 +27,13 @@ import setGlobal from './set-global';
import useDispatch from './use-dispatch';
import useGlobal from './use-global';
import withGlobal from './with-global';
import React = require('react');



type BooleanFunction = () => boolean;

interface ReactN extends TypeOfReact {
interface ReactN extends Omit<typeof React, 'Component' | 'default' | 'PureComponent'> {

<P extends {} = {}, S extends {} = {}, G extends {} = State, R extends {} = Reducers, SS = any>(
DecoratedComponent: React.ComponentClass<P, S>,
Expand All @@ -51,8 +52,6 @@ interface ReactN extends TypeOfReact {
reducers: AdditionalReducers<G, R>,
): BooleanFunction;

Component: ReactNComponentClass;

createProvider<G extends {} = State, R extends {} = Reducers>(
initialState?: G,
initialReducers?: R,
Expand All @@ -65,8 +64,6 @@ interface ReactN extends TypeOfReact {

getGlobal<G extends {} = State>(): G;

PureComponent: ReactNPureComponentClass;

removeCallback<G extends {} = State>(
callback: Callback<G>,
): boolean;
Expand Down Expand Up @@ -102,21 +99,45 @@ interface ReactN extends TypeOfReact {
}

declare namespace ReactNTypes {

interface Component<
P extends {} = {},
S extends {} = {},
G extends {} = State,
R extends {} = Reducers,
SS = any,
> extends ReactNComponent<P, S, G, R, SS> { }

interface ComponentClass<
P extends {} = {},
S extends {} = {},
G extends {} = State,
R extends {} = Reducers,
SS = any
> extends React.ComponentClass<P, S> {
new (props: P, context?: any): ReactNComponent<P, S, G, R, SS>;
}
SS = any,
> extends ReactNComponentClass<P, S, G, R, SS> { }

interface PureComponent<
P extends {} = {},
S extends {} = {},
G extends {} = State,
R extends {} = Reducers,
SS = any,
> extends ReactNPureComponent<P, S, G, R, SS> { }

interface PureComponentClass<
P extends {} = {},
S extends {} = {},
G extends {} = State,
R extends {} = Reducers,
SS = any,
> extends ReactNPureComponentClass<P, S, G, R, SS> { }

class Component { }
class ComponentClass { }
class PureComponent { }
class PureComponentClass { }
}

type TypeOfReact = typeof React;



export = Object.assign(reactn, React, {
Expand Down
20 changes: 10 additions & 10 deletions tests/components/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const testComponent = (

testMount(
class TestMount extends _Super<Props, {}, G, R> {
render() { return null; }
public render(): null { return null; }
}
);

Expand All @@ -33,8 +33,8 @@ const testComponent = (
testComponentWillUnmount(
'prototype',
class TestUnmountPrototype extends _Super {
componentWillUnmount() { spyUnmountPrototype(); }
render() { return null; }
public componentWillUnmount(): void { spyUnmountPrototype(); }
public render(): null { return null; }
},
spyUnmountPrototype,
);
Expand Down Expand Up @@ -65,8 +65,8 @@ const testComponent = (
testComponentWillUpdate(
'prototype',
class TestUpdatePrototype extends _Super<Props, {}, G, R> {
componentWillUpdate() { spyUpdatePrototype(); }
render() { return null; }
public componentWillUpdate(): void { spyUpdatePrototype(); }
public render(): null { return null; }
},
spyUpdatePrototype,
);
Expand Down Expand Up @@ -117,7 +117,7 @@ describe('Components', (): void => {
testMount(
reactn(
class DecoratedMount extends Component<Props, {}> {
render() { return null; }
public render(): null { return null; }
}
)
);
Expand All @@ -128,8 +128,8 @@ describe('Components', (): void => {
'prototype',
reactn(
class DecoratedCwuPrototype extends Component {
componentWillUnmount() { spyUnmountPrototype(); }
render() { return null; }
public componentWillUnmount(): void { spyUnmountPrototype(); }
public render(): null { return null; }
}
),
spyUnmountPrototype,
Expand Down Expand Up @@ -165,8 +165,8 @@ describe('Components', (): void => {
'prototype',
reactn(
class DecoratedCwuPrototype extends Component<Props, {}> {
componentWillUpdate() { spyUpdatePrototype(); }
render() { return null; }
public componentWillUpdate(): void { spyUpdatePrototype(); }
public render(): null { return null; }
}
),
spyUpdatePrototype,
Expand Down
5 changes: 3 additions & 2 deletions types/component-class.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { ComponentClass } from 'react';
import { Reducers, State } from '../default';
import { ReactNComponent, ReactNPureComponent } from './component';
import Omit from './omit';

export interface ReactNComponentClass<
P extends {} = {},
S extends {} = {},
G extends {} = State,
R extends {} = Reducers,
SS = any,
> extends ComponentClass<P, S> {
> extends Omit<ComponentClass<P, S>, 'constructor' | 'new'> {
new (props: P, context?: any): ReactNComponent<P, S, G, R, SS>;
}

Expand All @@ -18,6 +19,6 @@ export interface ReactNPureComponentClass<
G extends {} = State,
R extends {} = Reducers,
SS = any,
> extends ComponentClass<P, S> {
> extends Omit<ComponentClass<P, S>, 'constructor' | 'new'> {
new (props: P, context?: any): ReactNPureComponent<P, S, G, R, SS>;
}
3 changes: 3 additions & 0 deletions types/omit.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;

export default Omit;

0 comments on commit 0d1d9f0

Please sign in to comment.