@vendit-dev/thirdparty-adapters 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/readme.md +2 -129
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1,131 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ThirdParty-Adapters
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
adapter modules for third party PMS & CMS providers.
|
|
4
4
|
|
|
5
|
-
It comes with super light-weighted bundle with 0 dependencies.
|
|
6
|
-
|
|
7
|
-
## What is this?
|
|
8
|
-
|
|
9
|
-
This library exports the class named `PassivePromise` which works exactly like normal Promises, but can be resolved outside of promise executor context.
|
|
10
|
-
|
|
11
|
-
## Installation
|
|
12
|
-
|
|
13
|
-
`npm install passive-promise`
|
|
14
|
-
|
|
15
|
-
or
|
|
16
|
-
|
|
17
|
-
`yarn add passive-promise`
|
|
18
|
-
|
|
19
|
-
The library exported with esnext module syntax.
|
|
20
|
-
|
|
21
|
-
## Usage Examples
|
|
22
|
-
|
|
23
|
-
Just use exactly like normal promise, but returned promise (which is extended Promise class) also comes with the `resolve()` and `reject()` method in it, which you can use them to force resolve or reject the promise from outside.
|
|
24
|
-
|
|
25
|
-
All the chain methods such as then, catch, finally works as expected, but remind that the both resolve, reject method of any chained PassivePromise instance will propagate to the root PassivePromise instance regardless of its depth.
|
|
26
|
-
|
|
27
|
-
### Common Usage
|
|
28
|
-
|
|
29
|
-
```javascript
|
|
30
|
-
import PassivePromise from 'passive-promise';
|
|
31
|
-
|
|
32
|
-
(async () => {
|
|
33
|
-
const foo = new PassivePromise((resolve, reject) => setTimeout(() => resolve(1), 1000));
|
|
34
|
-
|
|
35
|
-
console.log(await foo); // 1 after 1 sec
|
|
36
|
-
|
|
37
|
-
const bar = new PassivePromise((resolve, reject) => setTimeout(() => resolve(1), 1000));
|
|
38
|
-
|
|
39
|
-
bar.resolve(-1);
|
|
40
|
-
|
|
41
|
-
console.log(await bar); // -1 immedietly
|
|
42
|
-
|
|
43
|
-
const baz = new PassivePromise((resolve, reject) => setTimeout(() => resolve(1), 1000));
|
|
44
|
-
|
|
45
|
-
baz.reject(0) // Unhandled promise rejection.
|
|
46
|
-
})()
|
|
47
|
-
|
|
48
|
-
(async () => {
|
|
49
|
-
const foo = new PassivePromise(() => {})
|
|
50
|
-
.then((fulfilled) => console.log(fulfilled));
|
|
51
|
-
|
|
52
|
-
foo.resolve(1); // 1
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const bar = new PassivePromise(() => {})
|
|
56
|
-
.then((fulfilled) => console.log(fulfilled))
|
|
57
|
-
.catch((errored) => console.log('Promise rejected!', errored));
|
|
58
|
-
|
|
59
|
-
bar.reject(-1); // Promise rejected! -1
|
|
60
|
-
|
|
61
|
-
const baz = new PassivePromise(() => {})
|
|
62
|
-
.then(
|
|
63
|
-
(fulfilled) => console.log(fulfilled),
|
|
64
|
-
(errored) => console.log('Promise rejected!', errored),
|
|
65
|
-
)
|
|
66
|
-
.finally(() => console.log('Finally.'));
|
|
67
|
-
|
|
68
|
-
baz.reject(-1) // Promise rejected! -1 Finally.
|
|
69
|
-
})()
|
|
70
|
-
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
### Chain propagation
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
```javascript
|
|
77
|
-
import PassivePromise from 'passive-promise';
|
|
78
|
-
|
|
79
|
-
(async () => {
|
|
80
|
-
const chainedPromise = new PassivePromise(() => {})
|
|
81
|
-
.then((firstRes) => {
|
|
82
|
-
console.log('first.');
|
|
83
|
-
})
|
|
84
|
-
.then((secondRes) => {
|
|
85
|
-
console.log('second.');
|
|
86
|
-
})
|
|
87
|
-
.then((thirdRes) => {
|
|
88
|
-
console.log('third.');
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
chainedPromise.resolve(1);
|
|
92
|
-
|
|
93
|
-
await chainedPromise; // first. second. third.
|
|
94
|
-
|
|
95
|
-
const middleChain = new PassivePromise(() => {})
|
|
96
|
-
.then((firstRes) => {
|
|
97
|
-
console.log('first.');
|
|
98
|
-
})
|
|
99
|
-
.then((secondRes) => {
|
|
100
|
-
console.log('second.');
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
middleChain.then((thirdRes) => {
|
|
104
|
-
console.log('third.');
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
// Regardless of position of PassivePromise instance in the chained promises, they always resolve root promise in the chain.
|
|
108
|
-
middleChain.resolve(1);
|
|
109
|
-
|
|
110
|
-
await middleChain; // first. second. third.
|
|
111
|
-
|
|
112
|
-
// If you want to resolve the instance itself rather than root instance, use passiveResolve() and passiveReject() instead.
|
|
113
|
-
|
|
114
|
-
const anotherChain = new PassivePromise(() => {})
|
|
115
|
-
.then((firstRes) => {
|
|
116
|
-
console.log('first.');
|
|
117
|
-
})
|
|
118
|
-
.then((secondRes) => {
|
|
119
|
-
console.log('second.');
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
anotherChain.then((thirdRes) => {
|
|
123
|
-
console.log('third.');
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
// We want to directly resolve this promise rather than the whole promise chain here.
|
|
127
|
-
anotherChain.passiveResolve(1);
|
|
128
|
-
|
|
129
|
-
await anotherChain; // third.
|
|
130
|
-
})()
|
|
131
|
-
```
|