Coder Social home page Coder Social logo

redmadrobot / flipper Goto Github PK

View Code? Open in Web Editor NEW
70.0 6.0 3.0 332 KB

Flipper is a simple and useful tool to deal with feature toggles

License: MIT License

Kotlin 100.00%
android android-library kotlin kotlin-android kotlin-library feature-toggles feature-flags feature-toggle

flipper's Introduction

Flipper

Android Weekly API Build Status Maven Central

Flipper is a simple and useful tool to deal with feature toggles. It's not some secret weapon but rather a set of best practices to work with flipping features in your application, which is shipped as a library.

Quick start

Add this library to your gradle config

implementation 'com.redmadrobot:flipper:1.0.6'

Create a class with a description of features

object Features {

    object Feature1 : Feature() {
        override val id = "Feature1"
    }
}

Create some simplest configuration describing which features are enabled and which features are disabled:

class HardcodedConfig : FlipperConfig {
    private val features = mapOf(
        Features.Feature1.id to true
    )

    override fun featureIsEnabled(feature: Feature): Boolean {
        return features[feature.id] ?: false
    }
}

If you want to manage your features with Firebase, look at this config example.

Init the library in your Application class

ToggleRouter.init(HardcodedConfig())

Choose the necessary "feature edge" and place a toggle point (flipper point in this library terms).

val feature1Button = (Button) findViewById(R.id.feature1_button)

feature1Button.flipperPoint(Features.Feature1)

...

feature1Button.setOnClickListener { openFeature1Screen() }

Run and enjoy!

Library components

  • Feature: base class for all your feature objects. You have to provide a unique identifier for each such object.
  • ToggleRouter: features orchestrator based on some variant of the configuration
  • FlipperConfig: base class for your variant of the feature toggle configuration
  • flipperPoint: Kotlin extension function which you should place at the edge of your feature

More information about the "feature edges"

When it comes to Android application, you have only three ways of transition between features.

  • tap on the view (swipe like a special case)
  • tap on the menu item
  • an external event driven by business logic

In fact, all components that trigger transitions are the edges of the features. So, to prevent transition between features, we've got to disable the border component. You can do it using extension functions on View and MenuItem or a top-level function with flipping code blocks.

Some examples

with(feature4_button) {
    setOnClickListener { findNavController().navigate(Feature1FragmentDirections.toFeature4()) }
    flipperPoint(Features.Feature4)
}
with(bottom_nav.menu) {
    findItem(R.id.feature1).flipperPoint(Features.Feature1)
    findItem(R.id.feature2).flipperPoint(Features.Feature2)
    findItem(R.id.feature3).flipperPoint(Features.Feature3)
}
flipperPoint(Features.Feature1) {
    Log.d("Flipper", "I'll appear only when feature1 is enabled.")
}
if(flipperPointIsEnabled(Features.Feature1)) {
    Log.d("Flipper", "Feature1 is enabled.")
} else {
    Log.d("Flipper", "Feature1 is disabled.")
}

Further reading

There is an almost "classic" article about feature toggles Feature Toggles (aka Feature Flags). You can read it to know more about this library underline concepts.

Feedback

In case you have faced any bug or have a useful suggestion for improvement of this library, feel free to create an issue.

LICENSE

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

flipper's People

Contributors

fi5t avatar osipxd avatar vasilevungureanu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

flipper's Issues

Composite flipper config

It would be great to have the ability to simply create complex flipper configs compositions.

We have three configs (in order of priority):

  1. debug - configured from in-app debug panel
  2. remote - values from Firebase remote config
  3. local - hardcoded default values

If value not found in debug config, it will get from remote config. If value not configured in remote config it will get from local.

Our current solution

class LocalFlipperConfig() : FlipperConfig { /*...*/ }

class RemoteFlipperConfig(localConfig: LocalFlipperConfig) : FlipperConfig { 
    override fun featureIsEnabled(feature: Feature): Boolean {
        return if (hasValue(feature.id)) ... else localConfig.featureIsEnabled(feature)
    }
}

class DebugFlipperConfig(remoteConfig: RemoteFlipperConfig) : FlipperConfig { 
    override fun featureIsEnabled(feature: Feature): Boolean {
        return if (hasValue(feature.id)) ... else remoteConfig.featureIsEnabled(feature)
    }
}

ToggleRouter.init(DebugFlipperConfig(RemoteFlipperConfig(LocalFlipperConfig())))

Desired solution

class LocalFlipperConfig() : FlipperConfig { /*...*/ }

class RemoteFlipperConfig() : FlipperConfig { /*...*/ }

class DebugFlipperConfig() : FlipperConfig { /*...*/ }

ToggleRouter.init(
    DebugFlipperConfig(), 
    RemoteFlipperConfig(), 
    LocalFlipperConfig()
)

README.md outdated?

Hey!

New to the project, but I think the version mentioned in adding this project to the gradle config is 1.0.6 while the latest release is 2.0.1

Something that should be changed?

Imrove the way Feature is created.

I think the usability of the library can be improved if you change

abstract class Feature {
    abstract val id: String
}

to

abstract class FeatureNew(internal val id: String)

So the users will be able to add features like this

object New : FeatureNew("Экран")

instead of this

object Old : Feature() {
    override val id: String = "Экран кэшбека. Отображать персональные предложения"
}

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.