creates a simple context object
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)
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>
}