create-ctx
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

create-ctx

creates a simple context object

usage

import create from 'create-ctx'
import { Event } from 'ts-typed-events'

type Data = Partial<{
  [index: string]: any
  test: string
  data2: string
  circular: Event<string>
}>

const initial: Data = {}

const ctx = create(
  initial,
  { create: () => '100' },
  {
    test: new Event<string>()
  }
)

ctx.ev.test.on(test => ctx.set({ test }))
ctx.ev.test.emit('100')

ctx.set({ data2: '500', circular: new Event })
console.log(ctx.data)

console.log(ctx.clean)

example of returned object

export interface ContextWrapper <Data, Methods> {
  data: Partial<Data>
  fn: Partial<Methods>
  ev: Events
  setFn(fn: Partial<Methods>): void
  get(): Context<Data, Methods>
  set (i: Partial<Data>): Partial<Data>
  clear(): void
  readonly clean: Partial<Data>
}

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.0.30latest

Version History

VersionDownloads (Last 7 Days)Published
0.0.30
0.0.20
0.0.10

Package Sidebar

Install

npm i create-ctx

Weekly Downloads

0

Version

0.0.3

License

MIT

Unpacked Size

4.27 kB

Total Files

6

Last publish

Collaborators

  • wizardsorb