1.0.35 • Published 3 years ago
omi-tools v1.0.35
omi-tools
Auxiliary tools for omi
| tools | params | returns | desc |
|---|---|---|---|
| rmIEFP | props: object | props(without internal events):object | remove internal events from props |
| HF.camel2kebab | name(camelCase/PascalCase): string | name(kebabCase): string | convert camelCase or PascalCase to kebabCase |
| OC.makeFC | tagName: string,render: (props: Omi.OmiProps<Props>, store: Store) => JSX.Element,lifeTimes?: Partial<IOmiLifetimes<Props, Store>>,extraStore?: Store | FunctionComponent: FCConstructor<Props, Store> | generate a component or element in the form of render-function declaration |
| OC.reactive | data: object | hooks: Function | generate some reactive data |
| OC.createContext | defaultValue: any | IOmiContext<T>: {Provider: ProviderConstructor<T>, Consumer: ConsumerConstructor} | generate Provider/Consumer ComponentConstructor |
| OC.useContext | context: {Provider: ProviderConstructor<T>, Consumer: ConsumerConstructor} | value: T | Context Consumer Hooks |
| OH.useMemo | callback: () => T,deps: any[],shouldUpdated?: (prevDeps: any[], nextDeps: any[]) => booleancontext?: WeElement Context | computedData: T | computed and memorize result at same dependencies |
| OH.useEffect | callback: () => T,deps: any[],context?: WeElement Context | void | It is similar to React.useEffect, but the context needs to be passed in manually |
Explanation
- desc: remove internal events like
onClickfrom props to avoid multiple binding times usecase:
import { Component, h, tag } from 'omi' import { rmIEFP } from 'omi-tools' import css from '_style.less' const tagName = 'o-title' interface ITitleProps { className?: string style?: string title: string onClick?: (e: MouseEvent) => void } declare global { namespace JSX { interface IntrinsicElements { [tagName]: Omi.Props & Partial<ITitleProps> } } } @tag(tagName) export default class Title extends Component<ITitleProps> { static css = css render(props: Omi.OmiProps<ITitleProps>) { return <h1 {...rmIEFP(props)}>{props.title}</h1> } }
- desc: convert variable name from camelCase or PascalCase form to kebabCase form
usecase:
import { HF } from 'omi-tools' const tagName = HF.camel2kebab('MyCustomElementName'); // > tagName: `my-custom-element-name`
- desc: generate a component or element in the form of render-function declaration
usecase:
import { OC, rmIEFP } from 'omi-tools' import css from '_style.less' const tagName = 'o-h1-title' interface ITitleProps { className?: string style?: string title: string onClick?: (e: MouseEvent) => void } declare global { namespace JSX { interface IntrinsicElements { [tagName]: Omi.Props & Partial<ITitleProps> } } } const Title = OC.makeFC<ITitleProps>( tagName, props => <h1 {...rmIEFP(props)}>{props.title}</h1>, { staticCss: css } ) export default Title
- desc: generate some reactive data
- usecase: https://codepen.io/w-xuefeng/pen/ZEKNyLm
- preview: https://codepen.io/w-xuefeng/full/ZEKNyLm
- desc: generate Provider/Consumer ComponentConstructor
- usecase: https://codepen.io/w-xuefeng/pen/LYyxqLo
- preview: https://codepen.io/w-xuefeng/full/LYyxqLo
- desc: context Consumer Hooks
- usecase: https://codepen.io/w-xuefeng/pen/LYyxqLo
- preview: https://codepen.io/w-xuefeng/full/LYyxqLo
- desc: computed and memorize result at same dependencies
- usecase: https://codepen.io/w-xuefeng/pen/mdmZJQb
- preview: https://codepen.io/w-xuefeng/full/mdmZJQb
- desc: It is similar to React.useEffect, but the
contextneeds to be passed in manually - usecase: https://codepen.io/w-xuefeng/pen/KKmjJJa
- preview: https://codepen.io/w-xuefeng/full/KKmjJJa
1.0.35
3 years ago
1.0.34
4 years ago
1.0.33
4 years ago
1.0.32
4 years ago
1.0.31
4 years ago
1.0.30
4 years ago
1.0.29
4 years ago
1.0.28
4 years ago
1.0.26
4 years ago
1.0.27
4 years ago
1.0.22
4 years ago
1.0.21
4 years ago
1.0.25
4 years ago
1.0.24
4 years ago
1.0.23
4 years ago
1.0.19
4 years ago
1.0.18
4 years ago
1.0.17
4 years ago
1.0.16
4 years ago
1.0.20
4 years ago
1.0.15
4 years ago
1.0.14
4 years ago
1.0.13
4 years ago
1.0.12
4 years ago
1.0.11
4 years ago
1.0.9
4 years ago
1.0.8
4 years ago
1.0.7
4 years ago
1.0.10
4 years ago
1.0.6
4 years ago
1.0.5
4 years ago
1.0.4
4 years ago
1.0.3
4 years ago
1.0.2
4 years ago
1.0.1
4 years ago
1.0.0
4 years ago