@@ -38,6 +38,8 @@ In this guide we explain how to use feature toggles in a JavaScript application
3838
3939First, install the FeatureProbe SDK as a dependency in your application.
4040
41+ NPM:
42+
4143``` js
4244npm install featureprobe- client- sdk- js -- save
4345```
@@ -52,14 +54,32 @@ Or via CDN:
5254
5355After you install and import the SDK, create a single, shared instance of the FeatureProbe sdk.
5456
57+ NPM:
58+
5559``` js
56- const user = new featureProbe.FPUser (" user" );
57- user .with (" key" , " value" );
60+ const uniqueUserId = /* uniqueUserId */ ;
61+ const user = new FPUser (uniqueUserId);
62+ user .with (" userId" , /* userId */ );
63+
64+ const fp = new FeatureProbe ({
65+ remoteUrl: " https://127.0.0.1:4007" ,
66+ clientSdkKey: /* clientSdkKey */
67+ user,
68+ });
69+ fp .start ();
70+ ```
71+
72+ Or via CDN:
73+
74+ ``` js
75+ const uniqueUserId = /* uniqueUserId */ ;
76+ const user = new featureProbe.FPUser (uniqueUserId);
77+ user .with (" userId" , /* userId */ );
5878
5979const fp = new featureProbe.FeatureProbe ({
60- remoteUrl: " https://127.0.0.1:4007" ,
61- clientSdkKey: ' #YOUR-CLIENT-SDK-KEY# ' ,
62- user,
80+ remoteUrl: " https://127.0.0.1:4007" ,
81+ clientSdkKey : /* clientSdkKey */
82+ user,
6383});
6484fp .start ();
6585```
@@ -69,27 +89,43 @@ fp.start();
6989You can use sdk to check which value this user will receive for a given feature flag.
7090
7191``` js
72- fp .on (' ready' , function () {
73- const result = fp .boolValue (' ui_demo_toggle ' , false );
74- if (result) {
75- do_some_thing ();
76- } else {
77- do_other_thing ();
78- }
79- const reason = fp .boolDetail (' ui_demo_toggle ' , false );
80- console .log (reason);
92+ fp .on (" ready" , function () {
93+ const result = fp .boolValue (/* toggleKey */ , false );
94+ if (result) {
95+ do_some_thing ();
96+ } else {
97+ do_other_thing ();
98+ }
99+ const reason = fp .boolDetail (/* toggleKey */ , false );
100+ console .log (reason);
81101})
82102```
83103
84104### Step 4. Unit Testing (Optional)
105+ NPM:
85106
86107``` js
87108test (" feature probe unit testing" , (done ) => {
88109 let fp = FeatureProbe .newForTest ({ testToggle: true });
89110 fp .start ();
90111
91112 fp .on (" ready" , function () {
92- let t = fp .boolValue (" testToggle" , false );
113+ let t = fp .boolValue (/* toggleKey */ , false );
114+ expect (t).toBe (true );
115+ done ();
116+ });
117+ });
118+ ```
119+
120+ Or via CDN:
121+
122+ ``` js
123+ test (" feature probe unit testing" , (done ) => {
124+ let fp = featureProbe .FeatureProbe .newForTest ({ testToggle: true });
125+ fp .start ();
126+
127+ fp .on (" ready" , function () {
128+ let t = fp .boolValue (/* toggleKey */ , false );
93129 expect (t).toBe (true );
94130 done ();
95131 });
0 commit comments