0.2.0 • Published 3 years ago

@pataflags/sdk-js v0.2.0

Weekly downloads
17
License
-
Repository
-
Last release
3 years ago

#Basic configuration

  • Basic use

      const apiKey = 'YOUR_API_KEY';
      const user = { id: 1 };
      const options = {};
      const client = PFClient.initialize(apiKey, user, options);
      client.onUpdated((features) => console.log(features));
      client.onError((error) => console.log(error));
    
      client.evaluate();
  • Initialize with user context

      // ...
      
      const user = { id: 1, context: { country: 'eu', gender: 'male', isPremium: true }};
      
      // ...
  • Add fallback when request takes more than 200 milliseconds

      // ...
      
      const options = { fallback: { feature1: true, feature4: true }, timeout: 200 };
      
      // ...

#Cache strategies

  • Network Only (default)

    When network is success will return features from network

      // ...
      
      const options = { strategy: 'networkOnly' };
      
      // ...
      

    Combining with fallback, when network fails will return features from fallback

      // ...
      
      const options = { strategy: 'networkOnly', fallback: { feature1: true, feature4: true } };
      
      // ...
      
  • Network First (tolerant with connection fails)

    When network is success will return features from network, if network fails will return features from last evaluation stored in cache, if cache is empty will return features from fallback

      // ...
      
      const options = { strategy: 'networkFirst' };
      
      // OR
      
      const options = { strategy: 'networkFirst', fallback: { feature1: true, feature4: true } };
      
      // ...
      
  • Stale while revalidate (bootstrapping 0 milliseconds)

    It will return instant features from last evaluation stored in cache while try to revalidate cache from network in background, if cache is empty will return features from fallback

      // ...
      
      const options = { strategy: 'staleWhileRevalidate' };
      
      // OR
      
      const options = { strategy: 'staleWhileRevalidate', fallback: { feature1: true, feature4: true } };
      
      // ...
      
  • Cache only (offline mode)

    It will return features from cache, if cache is empty will return features from fallback

      // ...
      
      const options = { strategy: 'cacheOnly' };
      
      // OR
      
      const options = { strategy: 'cacheOnly', fallback: { feature1: true, feature4: true } };
      
      // ...
0.2.0

3 years ago

0.1.0

3 years ago

0.0.11

3 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.2

4 years ago

0.0.1-h

4 years ago

0.0.1-g

4 years ago

0.0.1-f

4 years ago

0.0.1-e

4 years ago

0.0.1-d

4 years ago

0.0.1-c

4 years ago

0.0.1-b

4 years ago

0.0.1

4 years ago