{"id":19935160,"url":"https://github.com/optimizely/flag-dependencies-demo","last_synced_at":"2025-05-03T12:31:09.341Z","repository":{"id":71780288,"uuid":"491742811","full_name":"optimizely/flag-dependencies-demo","owner":"optimizely","description":null,"archived":true,"fork":false,"pushed_at":"2022-05-31T19:56:01.000Z","size":2058,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":36,"default_branch":"master","last_synced_at":"2025-03-01T12:17:28.794Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/optimizely.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-13T03:21:35.000Z","updated_at":"2023-09-26T16:15:03.000Z","dependencies_parsed_at":"2023-03-01T10:31:53.974Z","dependency_job_id":null,"html_url":"https://github.com/optimizely/flag-dependencies-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/optimizely%2Fflag-dependencies-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/optimizely%2Fflag-dependencies-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/optimizely%2Fflag-dependencies-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/optimizely%2Fflag-dependencies-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/optimizely","download_url":"https://codeload.github.com/optimizely/flag-dependencies-demo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252190759,"owners_count":21708948,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T23:18:59.270Z","updated_at":"2025-05-03T12:31:09.333Z","avatar_url":"https://github.com/optimizely.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# flag-dependencies-demo\n\nA [demonstration](https://optimizely.github.io/flag-dependencies-demo/) of a simple implementation of \"flag dependencies\" with Optimizely Full Stack. \n\nFor a quick walkthrough of this demo, check out this [video overview](https://www.loom.com/share/bee221cd914341a1ad86b062de991d4b).\n\n## Try it out\n\nCheck out the [interactive demo](https://optimizely.github.io/flag-dependencies-demo/).\n\nThe demo source code is in the [docs](/docs) directory in this repository. The flag dependency evaluation logic lives in [flag_dependencies.js](/docs/js/flag_dependencies.js). \n\n## Usage\n\n```js\n// Optimizely SDK\nimport \"https://unpkg.com/@optimizely/optimizely-sdk@4.9.1/dist/optimizely.browser.umd.min.js\";\n\n// Flag Dependency module\nimport * as deps from \"./flag_dependencies.js\";\n\n// Instantiate an Optimizely client\nlet optimizelyClient = optimizelySdk.createInstance({\n  sdkKey : \"LbmzK7viE2J2bP5ozmZR9\"\n});\n\n// Create a context object for user123\nlet user = optimizelyClient.createUserContext(\"user123\");\n\n// Decide my_flag without evaluating dependencies\nlet decision_without_dependencies = user.decide(\"my_flag\");\n\n// Evaluate my_flag's dependencies statelessly and decide my_flag according to its rules if \n// they are satisfied. Return the default variation if not.\nlet decision_with_dependencies = deps.decide()\n\n```\n\n## Specifying dependencies\n\nIn the following example, `dependent_flag` uses a [targeted rollout rule](https://docs.developers.optimizely.com/experimentation/v4.0.0-full-stack/docs/run-flag-deliveries) and would normally evaluate to **on** for everyone. \n\n\u003cp align=\"center\"\u003e\u003cimg width=\"600\" src=\"docs/images/dependent_flag.png\" /\u003e\u003c/p\u003e\n\nHowever, we've added a special `_depends_on` [flag variable](https://docs.developers.optimizely.com/experimentation/v4.0.0-full-stack/docs/create-flag-variations#prerequisite-create-default-variables) to specify that `dependent_flag` depends on `example_flag`.\n\n\u003cp align=\"center\"\u003e\u003cimg width=\"600\" src=\"docs/images/dependent_flag_variable.png\" /\u003e\u003c/p\u003e\n\nDependencies are specified in `_depends_on`'s [default value](https://docs.developers.optimizely.com/experimentation/v4.0.0-full-stack/docs/create-flag-variations#prerequisite-create-default-variables) as a comma-separated list of dependencies that each take one of the following forms:\n\n```js\n  \"flagKey\"              // This flag depends on flagKey being enabled\n  \"flagKey:variationKey\" // This flag depends on flagKey's variationKey variation\n```\n\nWhen a the `decide()` function exported by [flag_dependencies.js](https://github.com/optimizely/flag-dependencies-demo/blob/master/docs/js/flag_dependencies.js) is used to make a decision for `dependent_flag` (see [Usage](#usage)), its dependencies are evaluated first.\n\nIf all dependencies are satisifed, the decision returned will follow the flag's [delivery and experiment rules](https://docs.developers.optimizely.com/full-stack/v4.0/docs/create-flag-variations#use-flag-variations), as normal.\n\nIf one or more dependencies are not satisfied, the **default variation**, specified by the \"everyone else\" rule in the flag's configuration, is returned.\n\n\n\n\n## Disclaimer and Acknowledgements\n\nThis demo is meant to be used as inspiration for your own implementation of flag dependencies. It has not been tested extensively and **should not be run in any serious production environment**. If you find a bug, please [file an issue](https://github.com/optimizely/flag-dependencies-demo/issues) or (even better) [create a pull request](https://github.com/optimizely/flag-dependencies-demo/pulls).\n\nBuilt with gratitude using [Skeleton](http://getskeleton.com/), [Alpine.js](https://alpinejs.dev/), and [leader-line](https://anseki.github.io/leader-line/).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foptimizely%2Fflag-dependencies-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foptimizely%2Fflag-dependencies-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foptimizely%2Fflag-dependencies-demo/lists"}