Skip to content

Commit 604e2c4

Browse files
authored
feat(ready): added new method (#3)
* feat(ready): add new method add a new method waitUntilReady
1 parent 919eb45 commit 604e2c4

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

WeChat/FeatureProbe.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class FeatureProbe extends TinyEmitter {
2121
private user: FPUser;
2222
private toggles: { [key: string]: FPToggleDetail } | null;
2323
private timer?: NodeJS.Timeout;
24+
private readyPromise: Promise<void>;
25+
2426

2527
constructor() {
2628
super();
@@ -31,6 +33,13 @@ class FeatureProbe extends TinyEmitter {
3133
this.clientSdkKey = '';
3234
this.refreshInterval = 0;
3335
this.toggles = {};
36+
this.readyPromise = new Promise((resolve) => {
37+
const onReadyCallback = () => {
38+
this.off(EVENTS.READY, onReadyCallback);
39+
resolve();
40+
};
41+
this.on(EVENTS.READY, onReadyCallback);
42+
});
3443
}
3544

3645
public init({
@@ -79,6 +88,10 @@ class FeatureProbe extends TinyEmitter {
7988
clearInterval(this.timer);
8089
}
8190

91+
public waitUntilReady(): Promise<void> {
92+
return this.readyPromise;
93+
}
94+
8295
public boolValue(key: string, defaultValue: boolean): boolean {
8396
return this.toggleValue(key, defaultValue, "boolean");
8497
}
@@ -123,6 +136,11 @@ class FeatureProbe extends TinyEmitter {
123136
this.user = Object.assign({}, user);
124137
}
125138

139+
public logout() {
140+
const user = new FPUser();
141+
this.identifyUser(user);
142+
}
143+
126144
static newForTest(toggles: { [key: string]: any }): FeatureProbe {
127145
const fp = new FeatureProbe();
128146
fp.init({

example/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"name": "featureprobe-client-sdk-miniprogram",
2+
"name": "client-sdk-miniprogram",
33
"version": "1.0.0",
44
"description": "",
55
"main": ".eslintrc.js",
66
"dependencies": {
7-
"featureprobe-client-sdk-miniprogram": "^1.0.0"
7+
"featureprobe-client-sdk-miniprogram": "^1.0.1-alpha.3"
88
},
99
"devDependencies": {},
1010
"scripts": {

example/project.private.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
3-
"projectname": "feature-probe-miniprogram-sdk-demo",
3+
"projectname": "example",
44
"setting": {
55
"compileHotReLoad": true,
66
"urlCheck": false

0 commit comments

Comments
 (0)