Skip to content

Commit

Permalink
feat: release v1.1.0 - 更新README
Browse files Browse the repository at this point in the history
  • Loading branch information
lengfangbing committed Feb 12, 2022
1 parent ebe6182 commit 256488c
Showing 1 changed file with 41 additions and 27 deletions.
68 changes: 41 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,41 @@
```typescript
import createPipe from '@bell-crow/pipe-core';
const value = createPipe({
name: 'crow',
age: 3
name: 'crow',
age: 3
}, {
getValue(value) {
return { ...value }
},
getName(value) {
return value.name;
},
getAge(value) {
return value.age;
}
getName(value) {
return value.name;
},
getAge(value) {
return value.age;
},
getValue(value) {
return value;
}
});
value
.pipeStart()
.getAge(age => console.log(`age is ${age}`))
.getName(name => console.log(`name is ${name}`))
.getValue(value => console.log(`value is ${JSON.stringify(value)}`))
.getValue((_, update) => {
const value = { name: 'bell-crow', age: 1 };
update(value as typeof _);
console.log(`change value: ${JSON.stringify(value)}`);
})
.getValue(value => console.log(`changed value is ${JSON.stringify(value)}`))
.pipeEnd()
.then()
.catch();
.pipeStart()
.getAge(age => {
console.log(`first age is ${age}`);
return age + 1;
}))
.pipe<number>((age, update) => {
console.log(`changed age is ${age}}`);
update({ age: 99 });
})
.getName(name => {
console.log(`first name is ${name}`);
return { newName: name + Date.now() };
}))
.pipe<{ newName: string }>((name, update) => {
console.log(`changed name is ${name.newName}`);
update('pipe-crow');
})
.getValue(value => console.log(`changed value is ${value}`))
.pipeEnd()
.then()
.catch();
```

## Have any explain about the usage?
Expand Down Expand Up @@ -62,10 +70,15 @@ value
> ```
> The created pipe is one `pipeline`. We can do some process based on one piece of the pipe called `process function`.
> Every `process function` could provide two parameters. The first is the `real-time value`. The second is one function can `update the value`.
> The `process function` could provide a function called `pipe`. It would receive the return value of the `process function`. And the first `pipe`'s return value would be the parameter of the secord `pipe` function. The `pipe` also supports function to update value.
> ```typescript
> await value
> .pipeStart() // start the pipe
> .getValue(value => console.log(`value is ${JSON.stringify(value)}`))
> .getValue(value => {
> console.log(`value is ${JSON.stringify(value)}`);
> return value.name;
> })
> .pipe<string>(name => console.log(`value.name is ${name}`))
> .getValue((_, update) => {
> // update the value, the update is synchronous
> const value = { name: 'bell-crow', age: 1 };
Expand All @@ -79,5 +92,6 @@ value
## TODO
* [ ] one process can mix multiple piece of the pipe function
* [ ] append piece of the pipe function dynamic
* [x] one process can mix multiple piece of the pipe function
* [x] append piece of the pipe function dynamic
* [ ] type auto support for pipe function

0 comments on commit 256488c

Please sign in to comment.