Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@types/framework-x #8

Open
alex-dixon opened this issue Aug 30, 2019 · 0 comments
Open

@types/framework-x #8

alex-dixon opened this issue Aug 30, 2019 · 0 comments
Assignees
Labels
api documentation Improvements or additions to documentation

Comments

@alex-dixon
Copy link
Contributor

Suggest forking definitelytyped and creating @types/framework-x per instructions here:
https://github.com/DefinitelyTyped/DefinitelyTyped#create-a-new-package

We can publish our own type definitions, but this forces the IDEs of users of the library to resolve our definitions to the type definitions. This way there's at least the option to install types optionally and if they're not installed goto will resolve directly to source code.

I'll push a branch with the type defs but in case not here's what we have:

declare type Db = object

declare function getState(): Db

// declare interface FrameworkX {
//   getState(): Db
// }

declare module "framework-x" {
  export type EventName = string
  export type EventData = any
  export type Event = [EventName, EventData?]
  export type DbFn = (db: Db) => Db
  export type FxName = "db" | "dispatch" | string
  export type FxArg = any
  export type Effects = { db: DbFn | Db } & { [k in FxName]: FxArg }
    | [FxName, FxArg][]


  export function dispatch(...event: Event): void;
  export function dispatch(eventType: EventName, ...args: [any]): void;

  export type Coeffects = { db: Db } & { [k: string]: any }

  export type Handler = (cofx: Coeffects, eventType: EventName, args: EventData) => Effects | void

  export function regEventFx(eventType: EventName, handler: Handler): void;

  export interface Effect {
    (x: any): any
  }

  export function regFx(name: FxName, fn: Effect): void

  export function getState(): Db

  type StateListener = (db: Db) => void

  export function subscribeToState(fn: StateListener): void

  type EventListener = (type: string, payload: any, effects: any) => any

  export interface Store {
    getState(): Db

    dispatch(...event: Event): void;

    dispatch(eventType: EventName, ...args: [any]): void;

    regEventFx(eventType: EventName, handler: Handler): void;

    regFx(name: FxName, fn: Effect): void

    subscribeToState(fn: StateListener): void
  }

  export function createStore(initialState?: object): Store
}
@alex-dixon alex-dixon added documentation Improvements or additions to documentation api labels Aug 30, 2019
@alex-dixon alex-dixon self-assigned this Aug 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant