Skip to content

Commit

Permalink
# 4.4.0 2022-05-17
Browse files Browse the repository at this point in the history
* [design] turns [flow](/api?id=flow), [Flows](/api?id=flows),  [effect](/api?id=effect) and [avatar](/api?id=avatar) API to be official.
* [experience] add experience API [strict](/experience?id=strict) and [act](/experience?id=act).
  • Loading branch information
wangyi committed May 17, 2022
1 parent a713658 commit 50a151d
Show file tree
Hide file tree
Showing 23 changed files with 2,325 additions and 1,765 deletions.
77 changes: 77 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,83 @@ It returns a `effect` object, which provides `update` and `unmount` methods. The
To check more [details](/guides?id=effect).
## flow
A `ES6 decorator` function which is used for marking a method to be a work flow method.
```typescript
export type WorkFlow = (runtime:FlowRuntime)=>LaunchHandler;

declare type FlowFn =((...flows:WorkFlow[])=>MethodDecoratorCaller)&{
force:<S, T extends Model<S>>(target:T, workFlow?:WorkFlow)=>T,
error:<
S=any,
T extends Model<S>=Model<S>
>(model:T, listener:ErrorListener)=>(()=>void)
}

export declare const flow:FlowFn;
```
* flows - optional, used to control how to run a flow method. You can select them from [Flows](/experience?id=flows-experience).
* flow.force - property function, used to force a inside flow method running on a special `WorkFlow`, for example: `flow.force(this, Flows.latest()).flowMethod()`, if you want the inside flow method just work as part of the current running flow method, you can provide no `WorkFlow` param for it, for example: `flow.force(this).flowMethod()`.
* flow.error - property function, used to listen the error from `flow methods`.
return a decorator callback.
## Flows
A set class for storing common `WorkFlows`.
```typescript
export class Flows {

static default():WorkFlow;

static latest():WorkFlow;

static debounce(ms:number, leading?:boolean):WorkFlow;
}
```
* Flows.default - use default work flow, which just like `@flow()`.
* Flows.latest - to take state changes which is leaded by the newest calling of a flow method.
* Flows.debounce - to make the flow method work with a debounce effect.
## effect
The `ES6 decorator` usage of [addEffect](/api?id=addeffect). It makes the working instance of current class as effect target. If you want to listen to the state changes from a specific method, you can give it a callback which returns method as param.
```typescript
export declare function effect<S=any, T extends Model<S>=Model>(
method?:()=>(...args:any[])=>any,
):MethodDecoratorCaller
```

* method - optional, a callback which returns `Class.prototype.method` as the target method for state change listening.

## avatar

Create an avatar object for outside interfaces.

```typescript
export type Avatar<T extends Record<string, any>> = {
current:T,
implement:(impl:Partial<T>)=>()=>void;
};

export declare function avatar<
T extends Record<string, unknown>
>(interfaces:T):Avatar<T>;
```
* interfaces - provide a default simulate `interfaces object`, if the used function from implements is not exist, it will provide the right function for a replace.
return Avatar object:
* current - the current working interfaces object. If the used function from implements is not exist, it will take the right function from `interfaces object` for a replace.
* implement - callback, accept a implement object for `interfaces object`.
## experience
This API is used for using new features or APIs which are still in experience mode.
Expand Down
7 changes: 6 additions & 1 deletion docs/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,9 @@ in this version, `runtime.cache` used in MiddleWare is independent.

* [experience] remove experience API `flow.on`.
* [experience] add experience API `flow.force`.
* [experience] fix the problem about the type interface of `@effect`.
* [experience] fix the problem about the type interface of `@effect`.

# 4.4.0 2022-05-17

* [design] turns [flow](/api?id=flow), [Flows](/api?id=flows), [effect](/api?id=effect) and [avatar](/api?id=avatar) API to be official.
* [experience] add experience API [strict](/experience?id=strict) and [act](/experience?id=act).
Loading

0 comments on commit 50a151d

Please sign in to comment.