Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions packages/reffects/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
interface Event {
id: string;
payload?: object;
}

interface Effect {
[effectName: string]: object
}

interface Coeffect{
id: string;
data?: object;
}

type EventHandler = (coeffect?: Coeffect, payload?: object) => Effect;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should return an object with many Effects inside, not sure how to represent it in TypeScript :)

Copy link
Contributor

@mariosanchez mariosanchez Apr 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify, this is how an event handler return looks like:

return {
        'state.set': {
          todos: newTodos,
        },
        toast: {
          text: `"${text}" was marked as ${isDone ? 'undone' : 'done'}.`,
          milliseconds: 3000,
        },
      };


type EffectHandler = Function;

type CoeffectHandler = Function;

export function dispatch(event: Event): void;
export function dispatchMany(events: Event[]): void;
export function dispatchLater(event: Event): void;
export function registerEventHandler(eventId: string, handler: EventHandler, coeffectDescriptions?: Coeffect[]): void;
export function registerCoeffectHandler(coeffectId: string, handler: CoeffectHandler): void;
export function registerEffectHandler(effectId: string, handler: EffectHandler): void;
export function registerEventsDelegation(originalEvents: string[], targetEvent: string): void;
export function coeffect(id: string, data?: object): Coeffect;
export function getEffectHandler(effectId: string): EffectHandler;
export function getCoeffectHandler(coeffectId: string): CoeffectHandler;
export function getEventHandler(eventId: string): EventHandler;
1 change: 1 addition & 0 deletions packages/reffects/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"main": "dist/reffects.js",
"umd:main": "dist/reffects.umd.js",
"keywords": [],
"types": "index.d.ts",
"devDependencies": {
"@babel/core": "^7.4.3",
"@babel/preset-env": "^7.4.3",
Expand Down