Skip to content

Commit

Permalink
Merge pull request #188 from cerebral/fixedCircularTyping
Browse files Browse the repository at this point in the history
Fixed circular typing
  • Loading branch information
christianalfoni authored Jan 15, 2019
2 parents 5986e0a + 508ddf1 commit e8ed416
Show file tree
Hide file tree
Showing 43 changed files with 218 additions and 251 deletions.
4 changes: 3 additions & 1 deletion packages/node_modules/overmind-angular/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { EventType, Overmind, TApp, Configuration } from 'overmind'
import { NgZone } from '@angular/core'
import { IMutation } from 'proxy-state-tree'

export type TConnect<Config extends Configuration> = {
export interface IConnect<Config extends Configuration> {
state: TApp<Config>['state']
actions: TApp<Config>['actions']
effects: TApp<Config>['effects']
addMutationListener: (cb: (mutation: IMutation) => void) => () => void
}

Expand All @@ -31,6 +32,7 @@ export const createConnect = <A extends Overmind<any>>(overmind: A) => () => {
this.overmind = {
state: this.__tree.state,
actions: overmind.actions,
effects: overmind.effects,
addMutationListener: overmind.addMutationListener,
}
this.__shouldUpdatePaths = false
Expand Down
4 changes: 2 additions & 2 deletions packages/node_modules/overmind-devtools/src/overmind/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Overmind, TConfig } from 'overmind'
import { Overmind, IConfig } from 'overmind'
import { createHook } from 'overmind-react'

import * as actions from './actions'
Expand All @@ -13,7 +13,7 @@ const config = {
}

declare module 'overmind' {
interface IConfig extends TConfig<typeof config> {}
interface Config extends IConfig<typeof config> {}
}

export const overmind = new Overmind(config, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,4 +326,6 @@ export const forkEachMessage: (
) => Operator<AppMessage<any>[]> = (paths) =>
forEach(fork(({ value }) => value.type, paths) as Operator<AppMessage<any>>)

export const updateOperatorAsync = action<AsyncOperatorMessage>(() => {})
export const updateOperatorAsync: Operator<AsyncOperatorMessage> = action(
() => {}
)
20 changes: 10 additions & 10 deletions packages/node_modules/overmind-react/src/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Overmind, TAction } from 'overmind'
import { Overmind, IAction } from 'overmind'
import * as React from 'react'
import * as renderer from 'react-test-renderer'
import { TConnect, createConnect } from './'
import { IConnect, createConnect } from './'

describe('React', () => {
test('should connect state and actions to stateless components', () => {
Expand Down Expand Up @@ -29,11 +29,11 @@ describe('React', () => {

const app = new Overmind(config)

type Action<Input = void> = TAction<IConfig, Input>
interface Action<Input = void> extends IAction<IConfig, Input> {}

const connect = createConnect(app)

const Component: React.SFC<TConnect<IConfig>> = ({ overmind }) => {
const Component: React.SFC<IConnect<IConfig>> = ({ overmind }) => {
overmind.actions.doThis()
return <h1>{overmind.state.foo}</h1>
}
Expand Down Expand Up @@ -68,11 +68,11 @@ describe('React', () => {

const app = new Overmind(config)

type Action<Input = void> = TAction<IConfig, Input>
interface Action<Input = void> extends IAction<IConfig, Input> {}

const connect = createConnect(app)

class Component extends React.Component<TConnect<IConfig>> {
class Component extends React.Component<IConnect<IConfig>> {
componentDidMount() {
this.props.overmind.actions.doThis()
}
Expand Down Expand Up @@ -101,7 +101,7 @@ describe('React', () => {

const connect = createConnect(app)

class Component extends React.Component<TConnect<typeof config>> {
class Component extends React.Component<IConnect<typeof config>> {
render() {
const { overmind } = this.props

Expand All @@ -120,7 +120,7 @@ describe('React', () => {
const app = new Overmind({})
const connect = createConnect(app)

class FooComponent extends React.Component<TConnect<{}>> {
class FooComponent extends React.Component<IConnect<{}>> {
render() {
return <h1>hop</h1>
}
Expand Down Expand Up @@ -161,11 +161,11 @@ describe('React', () => {

const app = new Overmind(config)

type Action<Input = void> = TAction<IConfig, Input>
interface Action<Input = void> extends IAction<IConfig, Input> {}

const connect = createConnect(app)

class FooComponent extends React.Component<TConnect<typeof config>> {
class FooComponent extends React.Component<IConnect<typeof config>> {
shouldComponentUpdate(nextProps) {
return this.props.overmind !== nextProps.overmind
}
Expand Down
11 changes: 9 additions & 2 deletions packages/node_modules/overmind-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ type Omit<T, K extends keyof T> = Pick<
{ [P in K]: never } & { [x: string]: never; [x: number]: never })[keyof T]
>

export type TConnect<Config extends Configuration> = {
export interface IConnect<Config extends Configuration> {
overmind: {
state: TApp<Config>['state']
actions: TApp<Config>['actions']
effects: TApp<Config>['effects']
addMutationListener: (cb: (mutation: IMutation) => void) => () => void
}
}
Expand All @@ -44,6 +45,7 @@ export const createHook = <A extends Overmind<Configuration>>(
): (() => {
state: A['state']
actions: A['actions']
effects: A['effects']
addMutationListener: (cb: (mutation: IMutation) => void) => () => void
}) => {
let currentComponentInstanceId = 0
Expand Down Expand Up @@ -128,6 +130,7 @@ export const createHook = <A extends Overmind<Configuration>>(
return {
state: tree.state,
actions: overmind.actions,
effects: overmind.effects,
addMutationListener: overmind.addMutationListener,
}
}
Expand All @@ -140,7 +143,7 @@ export const createConnect = <A extends Overmind<Configuration>>(
component: IReactComponent<
Props & { overmind: { state: A['state']; actions: A['actions'] } }
>
): IReactComponent<Omit<Props & TConnect<A>, keyof TConnect<A>>> => {
): IReactComponent<Omit<Props & IConnect<A>, keyof IConnect<A>>> => {
let componentInstanceId = 0
const name = component.name
const populatedComponent = component as any
Expand Down Expand Up @@ -171,6 +174,7 @@ export const createConnect = <A extends Overmind<Configuration>>(
this.state = {
overmind: {
state: this.tree.state,
effects: overmind.effects,
actions: overmind.actions,
addMutationListener: overmind.addMutationListener,
onUpdate: this.onUpdate,
Expand All @@ -185,6 +189,7 @@ export const createConnect = <A extends Overmind<Configuration>>(
this.setState({
overmind: {
state: this.tree.state,
effects: overmind.effects,
actions: overmind.actions,
addMutationListener: overmind.addMutationListener,
onUpdate: this.onUpdate,
Expand Down Expand Up @@ -223,6 +228,7 @@ export const createConnect = <A extends Overmind<Configuration>>(
this.state = {
overmind: {
state: this.tree.state,
effects: overmind.effects,
actions: overmind.actions,
addMutationListener: overmind.addMutationListener,
onUpdate: this.onUpdate,
Expand Down Expand Up @@ -260,6 +266,7 @@ export const createConnect = <A extends Overmind<Configuration>>(
this.setState({
overmind: {
state: this.tree.state,
effects: overmind.effects,
actions: overmind.actions,
addMutationListener: overmind.addMutationListener,
onUpdate: this.onUpdate,
Expand Down
3 changes: 2 additions & 1 deletion packages/node_modules/overmind-vue/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EventType, Overmind } from 'overmind'
import { EventType } from 'overmind'

let nextComponentId = 0

Expand All @@ -19,6 +19,7 @@ export const createConnect = (overmind) => (options) => {
this.overmind = {
state: this.__tree.state,
actions: overmind.actions,
effects: overmind.effects,
addMutationListener: overmind.addMutationListener,
}
this.__tree.track(this.__onUpdate)
Expand Down
4 changes: 2 additions & 2 deletions packages/node_modules/overmind/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Configuration, TAction } from '../'
import { Configuration, IAction } from '../'

type SubType<Base, Condition> = Pick<
Base,
Expand Down Expand Up @@ -256,7 +256,7 @@ export function lazy<T extends LazyConfiguration, B = T>(
object
> & {
lazy: {
loadConfig: TAction<any, keyof T>
loadConfig: IAction<any, keyof T>
}
}
} {
Expand Down
56 changes: 15 additions & 41 deletions packages/node_modules/overmind/src/derived.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Overmind, TAction, TDerive, TStateObject } from './'
import { Overmind, IAction, IDerive, TStateObject } from './'

type State = {
foo: string
Expand All @@ -19,15 +19,10 @@ describe('Derived', () => {
state,
}

type Config = {
state: typeof state
}
type Config = typeof config

type Derive<Parent extends TStateObject, Value> = TDerive<
Config,
Parent,
Value
>
interface Derive<Parent extends TStateObject, Value>
extends IDerive<Config, Parent, Value> {}

const app = new Overmind(config)

Expand Down Expand Up @@ -59,12 +54,9 @@ describe('Derived', () => {
}
actions: typeof config.actions
}
type Action<Input = void> = TAction<Config, Input>
type Derive<Parent extends TStateObject, Value> = TDerive<
Config,
Parent,
Value
>
interface Action<Input = void> extends IAction<Config, Input> {}
interface Derive<Parent extends TStateObject, Value>
extends IDerive<Config, Parent, Value> {}

const app = new Overmind(config)
const trackStateTree = app.getTrackStateTree()
Expand Down Expand Up @@ -102,19 +94,10 @@ describe('Derived', () => {
changeFoo,
},
}
type Config = {
state: {
foo: string
upperFoo: string
}
actions: typeof config.actions
}
type Action<Input = void> = TAction<Config, Input>
type Derive<Parent extends TStateObject, Value> = TDerive<
Config,
Parent,
Value
>
type Config = typeof config
interface Action<Input = void> extends IAction<Config, Input> {}
interface Derive<Parent extends TStateObject, Value>
extends IDerive<Config, Parent, Value> {}

const app = new Overmind(config)

Expand All @@ -139,19 +122,10 @@ describe('Derived', () => {
changeFoo,
},
}
type Config = {
state: {
foo: string
upperFoo: string
}
actions: typeof config.actions
}
type Action<Input = void> = TAction<Config, Input>
type Derive<Parent extends TStateObject, Value> = TDerive<
Config,
Parent,
Value
>
type Config = typeof config
interface Action<Input = void> extends IAction<Config, Input> {}
interface Derive<Parent extends TStateObject, Value>
extends IDerive<Config, Parent, Value> {}

const app = new Overmind(config)

Expand Down
11 changes: 4 additions & 7 deletions packages/node_modules/overmind/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EventType, Overmind, TAction } from './'
import { EventType, Overmind, IAction } from './'
import { namespaced } from './config'

function toJSON(obj) {
Expand Down Expand Up @@ -60,12 +60,9 @@ function createDefaultOvermind() {
effects,
}

type Config = {
state: typeof state
actions: typeof actions
effects: typeof effects
}
type Action<Value = void> = TAction<Config, Value>
type Config = typeof config

interface Action<Value = void> extends IAction<Config, Value> {}

const app = new Overmind(config)

Expand Down
Loading

0 comments on commit e8ed416

Please sign in to comment.