1.0.35 • Published 4 years ago

omi-tools v1.0.35

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

omi-tools

Auxiliary tools for omi

NPM version NPM downloads

toolsparamsreturnsdesc
rmIEFPprops: objectprops(without internal events):objectremove internal events from props
HF.camel2kebabname(camelCase/PascalCase): stringname(kebabCase): stringconvert camelCase or PascalCase to kebabCase
OC.makeFCtagName: string,render: (props: Omi.OmiProps<Props>, store: Store) => JSX.Element,lifeTimes?: Partial<IOmiLifetimes<Props, Store>>,extraStore?: StoreFunctionComponent: FCConstructor<Props, Store>generate a component or element in the form of render-function declaration
OC.reactivedata: objecthooks: Functiongenerate some reactive data
OC.createContextdefaultValue: anyIOmiContext<T>: {Provider: ProviderConstructor<T>, Consumer: ConsumerConstructor}generate Provider/Consumer ComponentConstructor
OC.useContextcontext: {Provider: ProviderConstructor<T>, Consumer: ConsumerConstructor}value: TContext Consumer Hooks
OH.useMemocallback: () => T,deps: any[],shouldUpdated?: (prevDeps: any[], nextDeps: any[]) => booleancontext?: WeElement ContextcomputedData: Tcomputed and memorize result at same dependencies
OH.useEffectcallback: () => T,deps: any[],context?: WeElement ContextvoidIt is similar to React.useEffect, but the context needs to be passed in manually

Explanation

  • desc: remove internal events like onClick from 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
1.0.35

4 years ago

1.0.34

5 years ago

1.0.33

5 years ago

1.0.32

5 years ago

1.0.31

5 years ago

1.0.30

5 years ago

1.0.29

5 years ago

1.0.28

5 years ago

1.0.26

5 years ago

1.0.27

5 years ago

1.0.22

5 years ago

1.0.21

5 years ago

1.0.25

5 years ago

1.0.24

5 years ago

1.0.23

5 years ago

1.0.19

5 years ago

1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.20

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.10

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago