@evio/functional
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

@evio/functional

函数式hookable

Usage

import { Props, createComponent, Hook, execute } from '@evio/functional';

const hook = new Hook();

hook.use(FFF).on('test', (obj: { c: number }) => {
  obj.c += 99
})

async function FFF(props: Props<{}>) {
  const { c } = await props.useHook('test', () => {
    return {
      c: 1
    }
  })
  return 'ddd' + c
}

function ABC(props: Props<{}, [string]>) {
  return {
    name: 'abc',
    value: props.children[0]
  }
}

function KKK(props: Props<{}, [ReturnType<typeof ABC>]>) {
  return <ABC>
    <FFF />
  </ABC>
}

execute(<KKK />, hook).then(console.log)

output:

evioshen@shenyunjiedeMBP 111 % ts-node src/index.tsx       
{ name: 'abc', value: 'ddd100' }
evioshen@shenyunjiedeMBP 111 % tsc -d                      
evioshen@shenyunjiedeMBP 111 % node dist/index.js          
{ name: 'abc', value: 'ddd100' }

Readme

Keywords

none

Package Sidebar

Install

npm i @evio/functional

Weekly Downloads

0

Version

1.0.4

License

MIT

Unpacked Size

8.4 kB

Total Files

14

Last publish

Collaborators

  • evio