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

[Breaking] Flatten withEffects and aperture APIs #124

Merged
merged 7 commits into from
Nov 26, 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ The example below uses `refract-rxjs` to send data to localstorage.
Every time the `username` prop changes, its new value is sent into the stream. The stream debounces the input for two seconds, then maps it into an object (with a `type` of `localstorage`) under the key `value`. Each time an effect with the correct type is emitted from this pipeline, the handler calls `localstorage.setItem` with the effect's `name` and `value` properties.

```js
const aperture = initialProps => component => {
const aperture = component => {
return component.observe('username').pipe(
debounce(2000),
map(username => ({
Expand All @@ -104,7 +104,7 @@ const handler = initialProps => effect => {
}
}

const WrappedComponent = withEffects(handler)(aperture)(BaseComponent)
const WrappedComponent = withEffects(aperture, { handler })(BaseComponent)
```

### Aperture
Expand Down
18 changes: 7 additions & 11 deletions base/__tests__/inferno/callbag/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,16 @@ describe('refract-inferno-callbag', () => {
}

it('should create a HoC', () => {
const WithEffects = withEffects<Props, Effect>(handler)(aperture)(
() => <div />
)
withEffects<Props, Effect>(aperture, { handler })(() => <div />)
})

it('should observe component changes', () => {
const effectValueHandler = jest.fn()
const setValue = () => void 0
const WithEffects = withEffects<Props, Effect, Props & ExtraProps>(
() => effectValueHandler
)(aperture)(({ setValue, clickLink }) => (
aperture,
{ handler: () => effectValueHandler }
)(({ setValue, clickLink }) => (
<div>
<button onClick={() => setValue(10)} />
<a onClick={() => clickLink()} />
Expand Down Expand Up @@ -99,8 +98,7 @@ describe('refract-inferno-callbag', () => {
newProp: string
}
const BaseComponent = jest.fn().mockReturnValue(<div />)
const hander = () => () => void 0
const WithEffects = withEffects<Props, PropEffect, ChildProps>(hander)(
const WithEffects = withEffects<Props, PropEffect, ChildProps>(
asPropsAperture
)(BaseComponent)

Expand Down Expand Up @@ -133,8 +131,7 @@ describe('refract-inferno-callbag', () => {
newProp: string
}
const BaseComponent = jest.fn().mockReturnValue(<div />)
const hander = () => () => void 0
const WithEffects = withEffects<Props, PropEffect, ChildProps>(hander)(
const WithEffects = withEffects<Props, PropEffect, ChildProps>(
toPropsAperture
)(BaseComponent)

Expand All @@ -159,14 +156,13 @@ describe('refract-inferno-callbag', () => {
})

it('should render virtual elements', () => {
const hander = () => () => void 0
interface Props {
prop: string
}
const aperture = createRenderingAperture<VNode>(prop => (
<div>{prop}</div>
))
const WithEffects = withEffects<Props, VNode>(hander)(aperture)()
const WithEffects = withEffects<Props, VNode>(aperture)()

const node = mount(
// @ts-ignore
Expand Down
18 changes: 7 additions & 11 deletions base/__tests__/inferno/most/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,16 @@ describe('refract-inferno-most', () => {
}

it('should create a HoC', () => {
const WithEffects = withEffects<Props, Effect>(handler)(aperture)(
() => <div />
)
withEffects<Props, Effect>(aperture, { handler })(() => <div />)
})

it('should observe component changes', () => {
const effectValueHandler = jest.fn()
const setValue = () => void 0
const WithEffects = withEffects<Props, Effect, Props & ExtraProps>(
() => effectValueHandler
)(aperture)(({ setValue, pushEvent }) => (
aperture,
{ handler: () => effectValueHandler }
)(({ setValue, pushEvent }) => (
<div>
<button onClick={() => setValue(10)} />
<a onClick={pushEvent('linkClick')} />
Expand Down Expand Up @@ -99,8 +98,7 @@ describe('refract-inferno-most', () => {
newProp: string
}
const BaseComponent = jest.fn().mockReturnValue(<div />)
const hander = () => () => void 0
const WithEffects = withEffects<Props, PropEffect, ChildProps>(hander)(
const WithEffects = withEffects<Props, PropEffect, ChildProps>(
asPropsAperture
)(BaseComponent)

Expand Down Expand Up @@ -133,8 +131,7 @@ describe('refract-inferno-most', () => {
newProp: string
}
const BaseComponent = jest.fn().mockReturnValue(<div />)
const hander = () => () => void 0
const WithEffects = withEffects<Props, PropEffect, ChildProps>(hander)(
const WithEffects = withEffects<Props, PropEffect, ChildProps>(
toPropsAperture
)(BaseComponent)

Expand All @@ -159,14 +156,13 @@ describe('refract-inferno-most', () => {
})

it('should render virtual elements', () => {
const hander = () => () => void 0
interface Props {
prop: string
}
const aperture = createRenderingAperture<VNode>(prop => (
<div>{prop}</div>
))
const WithEffects = withEffects<Props, VNode>(hander)(aperture)()
const WithEffects = withEffects<Props, VNode>(aperture)()

const node = mount(
// @ts-ignore
Expand Down
18 changes: 7 additions & 11 deletions base/__tests__/inferno/rxjs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,16 @@ describe('refract-inferno-rxjs', () => {
}

it('should create a HoC', () => {
const WithEffects = withEffects<Props, Effect>(handler)(aperture)(
() => <div />
)
withEffects<Props, Effect>(aperture, { handler })(() => <div />)
})

it('should observe component changes', () => {
const effectValueHandler = jest.fn()
const setValue = () => void 0
const WithEffects = withEffects<Props, Effect, Props & ExtraProps>(
() => effectValueHandler
)(aperture)(({ setValue, clickLink }) => (
aperture,
{ handler: () => effectValueHandler }
)(({ setValue, clickLink }) => (
<div>
<button onClick={() => setValue(10)} />
<a onClick={() => clickLink()} />
Expand Down Expand Up @@ -99,8 +98,7 @@ describe('refract-inferno-rxjs', () => {
newProp: string
}
const BaseComponent = jest.fn().mockReturnValue(<div />)
const hander = () => () => void 0
const WithEffects = withEffects<Props, PropEffect, ChildProps>(hander)(
const WithEffects = withEffects<Props, PropEffect, ChildProps>(
asPropsAperture
)(BaseComponent)

Expand Down Expand Up @@ -133,8 +131,7 @@ describe('refract-inferno-rxjs', () => {
newProp: string
}
const BaseComponent = jest.fn().mockReturnValue(<div />)
const hander = () => () => void 0
const WithEffects = withEffects<Props, PropEffect, ChildProps>(hander)(
const WithEffects = withEffects<Props, PropEffect, ChildProps>(
toPropsAperture
)(BaseComponent)

Expand All @@ -159,14 +156,13 @@ describe('refract-inferno-rxjs', () => {
})

it('should render virtual elements', () => {
const hander = () => () => void 0
interface Props {
prop: string
}
const aperture = createRenderingAperture<VNode>(prop => (
<div>{prop}</div>
))
const WithEffects = withEffects<Props, VNode>(hander)(aperture)()
const WithEffects = withEffects<Props, VNode>(aperture)()

const node = mount(
// @ts-ignore
Expand Down
18 changes: 7 additions & 11 deletions base/__tests__/inferno/xstream/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,16 @@ describe('refract-inferno-xstream', () => {
}

it('should create a HoC', () => {
const WithEffects = withEffects<Props, Effect>(handler)(aperture)(
() => <div />
)
withEffects<Props, Effect>(aperture, { handler })(() => <div />)
})

it('should observe component changes', () => {
const effectValueHandler = jest.fn()
const setValue = () => void 0
const WithEffects = withEffects<Props, Effect, Props & ExtraProps>(
() => effectValueHandler
)(aperture)(({ setValue, clickLink }) => (
aperture,
{ handler: () => effectValueHandler }
)(({ setValue, clickLink }) => (
<div>
<button onClick={() => setValue(10)} />
<a onClick={() => clickLink()} />
Expand Down Expand Up @@ -99,8 +98,7 @@ describe('refract-inferno-xstream', () => {
newProp: string
}
const BaseComponent = jest.fn().mockReturnValue(<div />)
const hander = () => () => void 0
const WithEffects = withEffects<Props, PropEffect, ChildProps>(hander)(
const WithEffects = withEffects<Props, PropEffect, ChildProps>(
asPropsAperture
)(BaseComponent)

Expand Down Expand Up @@ -133,8 +131,7 @@ describe('refract-inferno-xstream', () => {
newProp: string
}
const BaseComponent = jest.fn().mockReturnValue(<div />)
const hander = () => () => void 0
const WithEffects = withEffects<Props, PropEffect, ChildProps>(hander)(
const WithEffects = withEffects<Props, PropEffect, ChildProps>(
toPropsAperture
)(BaseComponent)

Expand All @@ -159,14 +156,13 @@ describe('refract-inferno-xstream', () => {
})

it('should render virtual elements', () => {
const hander = () => () => void 0
interface Props {
prop: string
}
const aperture = createRenderingAperture<VNode>(prop => (
<div>{prop}</div>
))
const WithEffects = withEffects<Props, VNode>(hander)(aperture)()
const WithEffects = withEffects<Props, VNode>(aperture)()

const node = mount(
// @ts-ignore
Expand Down
8 changes: 3 additions & 5 deletions base/__tests__/preact/callbag/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@ describe('refract-preact-callbag', () => {
}

it('should create a HoC', () => {
const WithEffects = withEffects<Props, Effect>(handler)(aperture)(
() => <div />
)
withEffects<Props, Effect>(aperture, { handler })(() => <div />)
})

// it('should observe component changes', () => {
// const effectValueHandler = jest.fn()
// const setValue = () => void 0
// const WithEffects = withEffects<Props, Effect>(
// () => effectValueHandler
// )(aperture)(({ setValue, pushEvent }) => (
// aperture, { handler: () => effectValueHandler }
// )(({ setValue, pushEvent }) => (
// <div>
// <button onClick={() => setValue(10)} />
// <a onClick={pushEvent('linkClick')} />
Expand Down
8 changes: 3 additions & 5 deletions base/__tests__/preact/most/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@ describe('refract-preact-most', () => {
}

it('should create a HoC', () => {
const WithEffects = withEffects<Props, Effect>(handler)(aperture)(
() => <div />
)
withEffects<Props, Effect>(aperture, { handler })(() => <div />)
})

// it('should observe component changes', () => {
// const effectValueHandler = jest.fn()
// const setValue = () => void 0
// const WithEffects = withEffects<Props, Effect>(
// () => effectValueHandler
// )(aperture)(({ setValue, pushEvent }) => (
// aperture, { handler: () => effectValueHandler }
// )(({ setValue, pushEvent }) => (
// <div>
// <button onClick={() => setValue(10)} />
// <a onClick={pushEvent('linkClick')} />
Expand Down
8 changes: 3 additions & 5 deletions base/__tests__/preact/rxjs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@ describe('refract-preact-rxjs', () => {
}

it('should create a HoC', () => {
const WithEffects = withEffects<Props, Effect>(handler)(aperture)(
() => <div />
)
withEffects<Props, Effect>(aperture, { handler })(() => <div />)
})

// it('should observe component changes', () => {
// const effectValueHandler = jest.fn()
// const setValue = () => void 0
// const WithEffects = withEffects<Props, Effect>(
// () => effectValueHandler
// )(aperture)(({ setValue, pushEvent }) => (
// aperture, { handler: () => effectValueHandler }
// )(({ setValue, pushEvent }) => (
// <div>
// <button onClick={() => setValue(10)} />
// <a onClick={pushEvent('linkClick')} />
Expand Down
6 changes: 2 additions & 4 deletions base/__tests__/preact/xstream/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@ describe('refract-preact-xstream', () => {
}

it('should create a HoC', () => {
const WithEffects = withEffects<Props, Effect>(handler)(aperture)(
() => <div />
)
withEffects<Props, Effect>(aperture, { handler })(() => <div />)
})

// it('should observe component changes', () => {
// const effectValueHandler = jest.fn()
// const setValue = () => void 0
// const WithEffects = withEffects<Props, Effect>(
// () => effectValueHandler
// aperture, { handler: () => effectValueHandler }
// )(aperture)(({ setValue, pushEvent }) => (
// <div>
// <button onClick={() => setValue(10)} />
Expand Down
8 changes: 4 additions & 4 deletions base/__tests__/react/callbag/aperture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface ExtraProps {
clickLink: () => void
}

export const aperture: Aperture<Props, Effect> = props => component => {
export const aperture: Aperture<Props, Effect> = component => {
const value$ = component.observe<number>('value')
const valueSet$ = component.observe<number>('setValue')
const mount$ = component.mount
Expand Down Expand Up @@ -66,7 +66,7 @@ interface SinkProps {
export const asPropsAperture: Aperture<
SourceProps,
PropEffect<SinkProps>
> = () => component =>
> = component =>
pipe(
component.observe(),
map(({ prop }) => ({
Expand All @@ -78,7 +78,7 @@ export const asPropsAperture: Aperture<
export const toPropsAperture: Aperture<
SourceProps,
PropEffect<SinkProps>
> = () => component =>
> = component =>
pipe(
component.observe(),
map(({ prop }) => ({
Expand All @@ -90,7 +90,7 @@ export const toPropsAperture: Aperture<
export const createRenderingAperture = <VNode>(
render: (prop: string) => VNode
) => {
const aperture: Aperture<SourceProps, VNode> = () => component =>
const aperture: Aperture<SourceProps, VNode> = component =>
pipe(component.observe('prop'), map(render))

return aperture
Expand Down
Loading