Giter Site home page Giter Site logo

dusan-juranovic / ff-react-native-client-sdk Goto Github PK

View Code? Open in Web Editor NEW

This project forked from harness/ff-react-native-client-sdk

0.0 0.0 0.0 579 KB

License: Apache License 2.0

Java 30.70% JavaScript 1.26% TypeScript 23.37% Objective-C 7.38% Swift 34.63% Ruby 2.65%

ff-react-native-client-sdk's Introduction

Harness CF React Native SDK

Overview


Harness is a feature management platform that helps teams to build better software and to test features quicker.

Before you Begin

Harness Feature Flags (FF) is a feature management solution that enables users to change the software’s functionality, without deploying new code. FF uses feature flags to hide code or behaviours without having to ship new versions of the software. A feature flag is like a powerful if statement.

For more information, see https://harness.io/products/feature-flags/

To read more, see https://ngdocs.harness.io/category/vjolt35atg-feature-flags

To sign up, https://app.harness.io/auth/#/signup/


Setup

To install SDK, declare a dependency to project's package.json file:

"ff-react-native-client-sdk": "1.0.0",

Or using npm install:

$ npm install --save ff-react-native-client-sdk

For iOS, run the following commands from project root folder

$ cd ios
$ pod install

Then, you may import package to your project. The SDK is used via single instance exported from index.d.ts module

import cfClientInstance from 'ff-react-native-client-sdk';

Initialization

cfClientInstance is base instance that provides all the features of SDK. It is initialized with instances of CfConfiguration and CfTarget. All configuration fields are optional and if omitted they will be populated with default values by SDK.

import cfClientInstance, {CfConfiguration, CfTarget} from 'ff-react-native-client-sdk';

const client = cfClientInstance;

const cfConfiguration = new CfConfiguration();
cfConfiguration.streamEnabled = true;

const cfTarget = new CfTarget();
cfTarget.identifier = 'Harness'

const apiKey = "YOUR_API_KEY";

const result = await cfClientInstance.initialize(apiKey, cfConfiguration, cfTarget);

cfTarget represents a desired target for which we want features to be evaluated. identifier is mandatory field.

"YOUR_API_KEY" is an authentication key, needed for access to Harness services.

Your Harness SDK is now initialized. Congratulations!!!

Public API Methods

The Public API exposes a few methods that you can utilize:

  • async initialize(apiKey: string, config: CfConfiguration, target:CfTarget)

  • boolVariation(evalutionId: string, defaultValue?: boolean)

  • stringVariation(evalutionId: string, defaultValue?:string)

  • numberVariation(evalutionId: string, defaultValue?:number)

  • jsonVariation(evalutionId: string, defaultValue: any)

  • registerEventsListener(listener: (type: string, flags: any) => void)

  • unregisterListener(listener: (type: string, flags: any) => void)

  • destroy()

Fetch evaluation's value

It is possible to fetch a value for a given evaluation. Evaluation is performed based on different type. In case there is no evaluation with provided id, the default value is returned.

Use appropriate method to fetch the desired Evaluation of a certain type.

boolVariation(evaluationId: string, defaultValue?: boolean)

//get boolean evaluation
let evaluation = await client.boolVariation("demo_bool_evaluation", false)

numberVariation(evaluationId: string, defaultValue?:number)

//get number evaluation
let numberEvaluation = await client.numberVariation("demo_number_evaluation", 0)

stringVariation(evaluationId: string, defaultValue?:string)

//get string evaluaation
let stringEvaluation = await client.stringVariation("demo_string_evaluation", "default");

jsonVariation(evaluationId: string, defaultValue?: any)

//get json evaluation
let jsonEvaluation = await client.jsonVariation("demo_json_evaluation", {});

Register for events

This method provides a way to register a listener for different events that might be triggered by SDK, indicating specific change in SDK itself.

    client.registerEventsListener((type, flags) => {

    });

Each type will return a corresponding value as shown in the table below.

event type returns
"start" null
"end" null
"evaluation_polling" List
"evaluation_change" EvaluationResponse


Visit documentation for complete list of possible types and values they provide.

To avoid unexpected behaviour, when listener is not needed anymore, a caller should call client.unregisterListener(eventsListener) This way the sdk will remove desired listener from internal list.

Shutting down the SDK

To avoid potential memory leak, when SDK is no longer needed (when the app is closed, for example), a caller should call this method

client.destroy()

ff-react-native-client-sdk's People

Contributors

dusan-juranovic avatar meghamathur03 avatar puneetsar avatar rushabh-harness avatar tan-nhu avatar tanovicstef92 avatar trajce-bu avatar trajcestreamsoft avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.