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

Commit

Permalink
fix: not passing extra props to created component by
Browse files Browse the repository at this point in the history
typescript issue in the returned function of the hoc
  • Loading branch information
davidpa9708 committed Nov 9, 2018
1 parent 5b69857 commit 8fcb030
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/UniformComponent.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { mount } from "enzyme"
import { UniformComponent, UniformProps } from "./index"

describe("<UniformComponent>", () => {
class TestUniformComponent extends React.Component<UniformProps<{ bar: string }>> {
class TestUniformComponent extends React.Component<
UniformProps<{ bar: string }, { asdf?: string }>
> {
render() {
return <input onChange={ev => this.props.data.change.bar(ev.target.value)} type="string" />
}
Expand Down
8 changes: 3 additions & 5 deletions src/UniformComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import React, { ComponentClass, SFC } from "react"
import Data, { IData } from "handle-data-change"

export { IData }

export type IProps<D, P = {}> = {
value: D
onChange?: (newValue: D) => void
path?: string[]
} & P
} & (P | {})

export type UniformProps<D, P = {}> = {
data: IData<D>
} & P
} & (P | {})

function equal<T>(a: T, b: T) {
return a === b
Expand All @@ -24,7 +22,7 @@ export function UniformComponent<D, H>(
let uniValue: D = {} as D
let uniPath: string[]
let data = new Data<D>({} as D, uniOnChange)
return function<H>(props: IProps<D> & H) {
return function(props: IProps<D, H>) {
const { onChange, value, defaultValue, path, ...rest } = props as any
if (!equal(onChange, uniOnChange) || !equal(value, uniValue) || !equal(path, uniPath)) {
uniOnChange = onChange
Expand Down
7 changes: 6 additions & 1 deletion src/UniformSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import * as React from "react"
import { IProps } from "./UniformComponent"
import { SafeJoin, Omit } from "./type-helpers"

export type UniformOptionProps<T> = SafeJoin<JSX.IntrinsicElements["option"], { value: T }>

type IProps<D, P = {}> = {
value: D
onChange?: (newValue: D) => void
path?: string[]
} & P

export class UniformSelect<T extends string> extends React.Component<
IProps<
T,
Expand Down

0 comments on commit 8fcb030

Please sign in to comment.