Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support mapping data to props and replacing props #77

Merged
merged 7 commits into from
Sep 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 58 additions & 2 deletions base/__tests__/inferno/callbag/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ import { createElement } from 'inferno-create-element'
import {
withEffects,
Handler,
ObservableComponent
ObservableComponent,
PropEffect
} from '../../../../packages/refract-inferno-callbag/src'
import aperture, { Effect, Props } from '../../react/callbag/aperture'
import {
aperture,
toPropsAperture,
asPropsAperture,
Effect,
Props
} from '../../react/callbag/aperture'
import { mount } from 'enzyme'

describe('refract-inferno-callbag', () => {
Expand Down Expand Up @@ -80,4 +87,53 @@ describe('refract-inferno-callbag', () => {
type: 'Stop'
})
})

it('should map props to wrapped component', () => {
interface Props {
prop: string
}
interface ChildProps {
newProp: string
}
const BaseComponent = jest.fn().mockReturnValue(<div />)
const hander = () => () => void 0
const WithEffects = withEffects<Props, PropEffect, ChildProps>(hander)(
asPropsAperture
)(BaseComponent)

mount(
// @ts-ignore
<WithEffects prop="hello" />
)

const props = BaseComponent.mock.calls[0][0]

expect(props.prop).toBeUndefined()
expect(props.newProp).toBe('hello world')
})

it('should add props to wrapped component', () => {
interface Props {
prop: string
}
interface ChildProps {
prop: string
newProp: string
}
const BaseComponent = jest.fn().mockReturnValue(<div />)
const hander = () => () => void 0
const WithEffects = withEffects<Props, PropEffect, ChildProps>(hander)(
toPropsAperture
)(BaseComponent)

mount(
// @ts-ignore
<WithEffects prop="hello" />
)

const props = BaseComponent.mock.calls[0][0]

expect(props.prop).toBe('hello')
expect(props.newProp).toBe('hello world')
})
})
60 changes: 58 additions & 2 deletions base/__tests__/inferno/most/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ import { createElement } from 'inferno-create-element'
import {
withEffects,
Handler,
ObservableComponent
ObservableComponent,
PropEffect
} from '../../../../packages/refract-inferno-most/src'
import aperture, { Effect, Props } from '../../react/most/aperture'
import {
aperture,
toPropsAperture,
asPropsAperture,
Effect,
Props
} from '../../react/most/aperture'
import { mount } from 'enzyme'

describe('refract-inferno-most', () => {
Expand Down Expand Up @@ -80,4 +87,53 @@ describe('refract-inferno-most', () => {
type: 'Stop'
})
})

it('should map props to wrapped component', () => {
interface Props {
prop: string
}
interface ChildProps {
newProp: string
}
const BaseComponent = jest.fn().mockReturnValue(<div />)
const hander = () => () => void 0
const WithEffects = withEffects<Props, PropEffect, ChildProps>(hander)(
asPropsAperture
)(BaseComponent)

mount(
// @ts-ignore
<WithEffects prop="hello" />
)

const props = BaseComponent.mock.calls[0][0]

expect(props.prop).toBeUndefined()
expect(props.newProp).toBe('hello world')
})

it('should add props to wrapped component', () => {
interface Props {
prop: string
}
interface ChildProps {
prop: string
newProp: string
}
const BaseComponent = jest.fn().mockReturnValue(<div />)
const hander = () => () => void 0
const WithEffects = withEffects<Props, PropEffect, ChildProps>(hander)(
toPropsAperture
)(BaseComponent)

mount(
// @ts-ignore
<WithEffects prop="hello" />
)

const props = BaseComponent.mock.calls[0][0]

expect(props.prop).toBe('hello')
expect(props.newProp).toBe('hello world')
})
})
60 changes: 58 additions & 2 deletions base/__tests__/inferno/rxjs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ import { createElement } from 'inferno-create-element'
import {
withEffects,
Handler,
ObservableComponent
ObservableComponent,
PropEffect
} from '../../../../packages/refract-inferno-rxjs/src'
import aperture, { Effect, Props } from '../../react/rxjs/aperture'
import {
aperture,
toPropsAperture,
asPropsAperture,
Effect,
Props
} from '../../react/rxjs/aperture'
import { mount } from 'enzyme'

describe('refract-inferno-rxjs', () => {
Expand Down Expand Up @@ -80,4 +87,53 @@ describe('refract-inferno-rxjs', () => {
type: 'Stop'
})
})

it('should map props to wrapped component', () => {
interface Props {
prop: string
}
interface ChildProps {
newProp: string
}
const BaseComponent = jest.fn().mockReturnValue(<div />)
const hander = () => () => void 0
const WithEffects = withEffects<Props, PropEffect, ChildProps>(hander)(
asPropsAperture
)(BaseComponent)

mount(
// @ts-ignore
<WithEffects prop="hello" />
)

const props = BaseComponent.mock.calls[0][0]

expect(props.prop).toBeUndefined()
expect(props.newProp).toBe('hello world')
})

it('should add props to wrapped component', () => {
interface Props {
prop: string
}
interface ChildProps {
prop: string
newProp: string
}
const BaseComponent = jest.fn().mockReturnValue(<div />)
const hander = () => () => void 0
const WithEffects = withEffects<Props, PropEffect, ChildProps>(hander)(
toPropsAperture
)(BaseComponent)

mount(
// @ts-ignore
<WithEffects prop="hello" />
)

const props = BaseComponent.mock.calls[0][0]

expect(props.prop).toBe('hello')
expect(props.newProp).toBe('hello world')
})
})
60 changes: 58 additions & 2 deletions base/__tests__/inferno/xstream/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ import { createElement } from 'inferno-create-element'
import {
withEffects,
Handler,
ObservableComponent
ObservableComponent,
PropEffect
} from '../../../../packages/refract-inferno-xstream/src'
import aperture, { Effect, Props } from '../../react/xstream/aperture'
import {
aperture,
toPropsAperture,
asPropsAperture,
Effect,
Props
} from '../../react/xstream/aperture'
import { mount } from 'enzyme'

describe('refract-inferno-xstream', () => {
Expand Down Expand Up @@ -80,4 +87,53 @@ describe('refract-inferno-xstream', () => {
type: 'Stop'
})
})

it('should map props to wrapped component', () => {
interface Props {
prop: string
}
interface ChildProps {
newProp: string
}
const BaseComponent = jest.fn().mockReturnValue(<div />)
const hander = () => () => void 0
const WithEffects = withEffects<Props, PropEffect, ChildProps>(hander)(
asPropsAperture
)(BaseComponent)

mount(
// @ts-ignore
<WithEffects prop="hello" />
)

const props = BaseComponent.mock.calls[0][0]

expect(props.prop).toBeUndefined()
expect(props.newProp).toBe('hello world')
})

it('should add props to wrapped component', () => {
interface Props {
prop: string
}
interface ChildProps {
prop: string
newProp: string
}
const BaseComponent = jest.fn().mockReturnValue(<div />)
const hander = () => () => void 0
const WithEffects = withEffects<Props, PropEffect, ChildProps>(hander)(
toPropsAperture
)(BaseComponent)

mount(
// @ts-ignore
<WithEffects prop="hello" />
)

const props = BaseComponent.mock.calls[0][0]

expect(props.prop).toBe('hello')
expect(props.newProp).toBe('hello world')
})
})
2 changes: 1 addition & 1 deletion base/__tests__/preact/callbag/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Handler,
ObservableComponent
} from '../../../../packages/refract-preact-callbag/src'
import aperture, { Effect, Props } from '../../react/callbag/aperture'
import { aperture, Effect, Props } from '../../react/callbag/aperture'
import { mount } from 'enzyme'

describe('refract-preact-callbag', () => {
Expand Down
2 changes: 1 addition & 1 deletion base/__tests__/preact/most/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Handler,
ObservableComponent
} from '../../../../packages/refract-preact-most/src'
import aperture, { Effect, Props } from '../../react/most/aperture'
import { aperture, Effect, Props } from '../../react/most/aperture'
import { mount } from 'enzyme'

describe('refract-preact-most', () => {
Expand Down
2 changes: 1 addition & 1 deletion base/__tests__/preact/rxjs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Handler,
ObservableComponent
} from '../../../../packages/refract-preact-rxjs/src'
import aperture, { Effect, Props } from '../../react/rxjs/aperture'
import { aperture, Effect, Props } from '../../react/rxjs/aperture'
import { mount } from 'enzyme'

describe('refract-preact-rxjs', () => {
Expand Down
2 changes: 1 addition & 1 deletion base/__tests__/preact/xstream/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Handler,
ObservableComponent
} from '../../../../packages/refract-preact-xstream/src'
import aperture, { Effect, Props } from '../../react/xstream/aperture'
import { aperture, Effect, Props } from '../../react/xstream/aperture'
import { mount } from 'enzyme'

describe('refract-preact-xstream', () => {
Expand Down
42 changes: 38 additions & 4 deletions base/__tests__/react/callbag/aperture.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { merge, map } from 'callbag-basics'
import { merge, map, pipe } from 'callbag-basics'

import { Aperture } from '../../../../packages/refract-callbag/src'
import {
Aperture,
toProps,
asProps,
PropEffect
} from '../../../../packages/refract-callbag/src'

export interface Effect {
type: string
Expand All @@ -12,7 +17,7 @@ export interface Props {
setValue: (value: number) => void
}

const aperture: Aperture<Props, Effect> = props => component => {
export const aperture: Aperture<Props, Effect> = props => component => {
const value$ = component.observe<number>('value')
const valueSet$ = component.observe<number>('setValue')
const mount$ = component.mount
Expand Down Expand Up @@ -44,4 +49,33 @@ const aperture: Aperture<Props, Effect> = props => component => {
)
}

export default aperture
export interface SourceProps {
prop: string
}
interface SinkProps {
newProp: string
}

export const asPropsAperture: Aperture<
SourceProps,
PropEffect<SinkProps>
> = () => component =>
pipe(
component.observe(),
map(({ prop }) => ({
newProp: `${prop} world`
})),
map(asProps)
)

export const toPropsAperture: Aperture<
SourceProps,
PropEffect<SinkProps>
> = () => component =>
pipe(
component.observe(),
map(({ prop }) => ({
newProp: `${prop} world`
})),
map(toProps)
)
Loading