-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(project): improve typings and fix typo (#1802)
- Loading branch information
Showing
28 changed files
with
134 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from './shared/externals' | ||
export * from './models/types' | ||
export * from './effects' | ||
export * from './types' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export type { Form } from './Form' | ||
export type { Field } from './Field' | ||
export type { Query } from './Query' | ||
export type { Heart } from './Heart' | ||
export type { Graph } from './Graph' | ||
export type { LifeCycle } from './LifeCycle' | ||
export type { ArrayField } from './ArrayField' | ||
export type { ObjectField } from './ObjectField' | ||
export type { VoidField } from './VoidField' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,2 @@ | ||
import React, { forwardRef, memo, Fragment } from 'react' | ||
import hoistNonReactStatics from 'hoist-non-react-statics' | ||
import { useObserver } from './hooks' | ||
import { IObserverOptions, IObserverProps } from './types' | ||
|
||
export function observer<P, Options extends IObserverOptions>( | ||
component: React.FunctionComponent<P>, | ||
options?: Options | ||
): React.MemoExoticComponent< | ||
React.FunctionComponent< | ||
Options extends { forwardRef: true } | ||
? P & { | ||
ref?: 'ref' extends keyof P ? P['ref'] : React.RefAttributes<any> | ||
} | ||
: React.PropsWithoutRef<P> | ||
> | ||
> { | ||
const realOptions = { | ||
forwardRef: false, | ||
...options, | ||
} | ||
|
||
const wrappedComponent = realOptions.forwardRef | ||
? forwardRef((props: any, ref: any) => { | ||
return useObserver(() => component({ ...props, ref }), realOptions) | ||
}) | ||
: (props: any) => { | ||
return useObserver(() => component(props), realOptions) | ||
} | ||
|
||
const memoComponent = memo(wrappedComponent) | ||
|
||
hoistNonReactStatics(memoComponent, component) | ||
|
||
if (realOptions.displayName) { | ||
memoComponent.displayName = realOptions.displayName | ||
} | ||
|
||
return memoComponent | ||
} | ||
|
||
export const Observer = observer((props: IObserverProps) => { | ||
const children = | ||
typeof props.children === 'function' ? props.children() : props.children | ||
return React.createElement(Fragment, {}, children) | ||
}) | ||
export * from './observer' | ||
export * from './types' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React, { forwardRef, memo, Fragment } from 'react' | ||
import hoistNonReactStatics from 'hoist-non-react-statics' | ||
import { useObserver } from './hooks' | ||
import { IObserverOptions, IObserverProps } from './types' | ||
|
||
export function observer<P, Options extends IObserverOptions>( | ||
component: React.FunctionComponent<P>, | ||
options?: Options | ||
): React.MemoExoticComponent< | ||
React.FunctionComponent< | ||
Options extends { forwardRef: true } | ||
? P & { | ||
ref?: 'ref' extends keyof P ? P['ref'] : React.RefAttributes<any> | ||
} | ||
: React.PropsWithoutRef<P> | ||
> | ||
> { | ||
const realOptions = { | ||
forwardRef: false, | ||
...options, | ||
} | ||
|
||
const wrappedComponent = realOptions.forwardRef | ||
? forwardRef((props: any, ref: any) => { | ||
return useObserver(() => component({ ...props, ref }), realOptions) | ||
}) | ||
: (props: any) => { | ||
return useObserver(() => component(props), realOptions) | ||
} | ||
|
||
const memoComponent = memo(wrappedComponent) | ||
|
||
hoistNonReactStatics(memoComponent, component) | ||
|
||
if (realOptions.displayName) { | ||
memoComponent.displayName = realOptions.displayName | ||
} | ||
|
||
return memoComponent | ||
} | ||
|
||
export const Observer = observer((props: IObserverProps) => { | ||
const children = | ||
typeof props.children === 'function' ? props.children() : props.children | ||
return React.createElement(Fragment, {}, children) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './observer' | ||
export * from './hooks' | ||
export * from './types' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.