MiSikora / laboratory

Feature flags for multi-module Kotlin Android projects

Home Page:https://mehow.io/laboratory/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Laboratory ⚗️

Feature flags for multi-module Kotlin Android projects.

Please visit project website for the full documentation and the changelog.

TLDR

Add Laboratory dependency to your project.

repositories {
  mavenCentral()
}

dependencies {
  implementation "io.mehow.laboratory:laboratory:1.1.0"
}

Enable Java 8 support.

android {
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_17
    targetCompatibility JavaVersion.VERSION_17
  }

  kotlinOptions {
    jvmTarget = JavaVersion.VERSION_17.toString()
    freeCompilerArgs += [
        "-Xjvm-default=all",
    ]
  }
}

Define your feature flags.

enum class AuthType : Feature<AuthType> {
  None,
  Fingerprint,
  Retina,
  Face;

  public override val defaultOption get() = Fingerprint
}

Start using them in the application.

suspend fun main() {
  // A high-level API for interaction with feature flags
  val laboratory = Laboratory.inMemory()

  // Set AuthType option to Fingerprint
  val success = laboratory.setOption(AuthType.Fingerprint)

  // Check what is the current option of AuthType
  val currentAuthType = laboratory.experiment<AuthType>()

  // Check if the current option of AuthType is equal to Face
  val isFaceAuth = laboratory.experimentIs(AuthType.Face)

  // Observe changes to the AuthType feature flag
  laboratory.observe<AuthType>()
      .onEach { option -> println("AuthType: $option") }
      .launchIn(GlobalScope)
}

License

Copyright 2020 Michał Sikora

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

Feature flags for multi-module Kotlin Android projects

https://mehow.io/laboratory/

License:Apache License 2.0


Languages

Language:Kotlin 98.9%Language:Shell 0.9%Language:HTML 0.1%Language:CSS 0.1%