{"id":15573605,"url":"https://github.com/jedireza/flux-constant","last_synced_at":"2025-07-30T08:10:53.536Z","repository":{"id":25642107,"uuid":"29077484","full_name":"jedireza/flux-constant","owner":"jedireza","description":":package: Unique constants for Flux apps","archived":false,"fork":false,"pushed_at":"2016-09-08T06:16:52.000Z","size":16,"stargazers_count":18,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-24T02:12:07.304Z","etag":null,"topics":["flux","flux-constant","javascript"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jedireza.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-11T01:26:35.000Z","updated_at":"2023-07-25T13:54:30.000Z","dependencies_parsed_at":"2022-08-24T14:10:13.126Z","dependency_job_id":null,"html_url":"https://github.com/jedireza/flux-constant","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/jedireza/flux-constant","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedireza%2Fflux-constant","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedireza%2Fflux-constant/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedireza%2Fflux-constant/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedireza%2Fflux-constant/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jedireza","download_url":"https://codeload.github.com/jedireza/flux-constant/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jedireza%2Fflux-constant/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267834811,"owners_count":24151642,"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","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["flux","flux-constant","javascript"],"created_at":"2024-10-02T18:13:42.737Z","updated_at":"2025-07-30T08:10:53.505Z","avatar_url":"https://github.com/jedireza.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# flux-constant\n\nUnique constants for Flux apps.\n\n[![Build Status](https://travis-ci.org/jedireza/flux-constant.svg?branch=master)](https://travis-ci.org/jedireza/flux-constant)\n[![devDependency Status](https://david-dm.org/jedireza/flux-constant/dev-status.svg?theme=shields.io)](https://david-dm.org/jedireza/flux-constant#info=devDependencies)\n\n\n## Install\n\n```js\n$ npm install flux-constant\n```\n\n\n## Usage\n\nCreate constants one at a time.\n\n```js\nvar FluxConstant = require('flux-constant');\n\nvar IMPORTANT_THING = new FluxConstant('IMPORTANT_THING');\n\nconsole.log(IMPORTANT_THING);\n// { name: 'IMPORTANT_THING' }\n\nconsole.log(IMPORTANT_THING.toString());\n// IMPORTANT_THING\n```\n\nOr create a set of them.\n\n```js\nvar FluxConstant = require('flux-constant');\n\nvar Set = FluxConstant.set([\n    'SEND_REQUEST',\n    'RECEIVE_RESPONSE'\n]);\n\nconsole.log(Set);\n/*\n{\n    SEND_REQUEST: { name: 'SEND_REQUEST' },\n    RECEIVE_RESPONSE: { name: 'RECEIVE_RESPONSE' }\n}\n*/\n\nconsole.log(Set.SEND_REQUEST instanceof FluxConstant);\n// true\n```\n\n\n## Why\n\nWith a Flux application you may have a set of constants such as:\n\n```js\nvar ContactConstants = {\n    ActionTypes: {\n        SEND_REQUEST: 'SEND_REQUEST',\n        RECEIVE_RESPONSE: 'RECEIVE_RESPONSE'\n    }\n};\n\nmodule.exports = ContactConstants;\n```\n\nYou may have another set of constants that are really similar, but unreleated.\n\n```js\nvar SignupConstants = {\n    ActionTypes: {\n        SEND_REQUEST: 'SEND_REQUEST',\n        RECEIVE_RESPONSE: 'RECEIVE_RESPONSE'\n    }\n};\n\nmodule.exports = SignupConstants;\n```\n\nWe just created action types that could collide though. Let's compare a bit:\n\n```js\nvar ContactConstants = require('./ContactConstants');\nvar SignupConstants = require('./SignupConstants');\n\nContactActionTypes = ContactConstants.ActionTypes;\nSignupActionTypes = SignupConstants.ActionTypes;\n\nconsole.log(ContactActionTypes.SEND_REQUEST === SignupActionTypes.SEND_REQUEST);\n// true\n```\n\nThat's not exactly what we wanted. This could bite us if we use these two sets\nof constants in the same process.\n\nFor example, if a Flux store was depending on these constants, it may take\naction on a payload it didn't intend to. This happens because we're just\ncomparing strings.\n\nOne way to fix this is creating longer, more unique names:\n\n```js\nvar ContactConstants = {\n    ActionTypes: {\n        CONTACT_SEND_REQUEST: 'CONTACT_SEND_REQUEST',\n        CONTACT_RECEIVE_RESPONSE: 'CONTACT_RECEIVE_RESPONSE'\n    }\n};\n\nmodule.exports = ContactConstants;\n```\n\nThis doesn't seem like a great way to move forward though. These names can get\nout of control as the application grows. Also, prefixing with `CONTACT_` feels\nlike duplicating unnecessary information.\n\nSo instead of passing around strings let's create objects that are unique\n(`new`). And best of all we can keep the simpler naming conventions.\n\n```js\nvar FluxConstant = require('flux-constant');\n\nvar ContactConstants = {\n    ActionTypes: {\n        SEND_REQUEST: new FluxConstant('SEND_REQUEST'),\n        RECEIVE_RESPONSE: new FluxConstant('RECEIVE_RESPONSE')\n    }\n};\n\nmodule.exports = ContactConstants;\n```\n\nWe'll do the same thing as above but demonstrate the `set` shortcut.\n\n```js\nvar FluxConstant = require('flux-constant');\n\nvar SignupConstants = {\n    ActionTypes: FluxConstant.set([\n        'SEND_REQUEST',\n        'RECEIVE_RESPONSE'\n    ])\n};\n\nmodule.exports = SignupConstants;\n```\n\nAnd now they won't collide.\n\n```js\nvar ContactConstants = require('./ContactConstants');\nvar SignupConstants = require('./SignupConstants');\n\nContactActionTypes = ContactConstants.ActionTypes;\nSignupActionTypes = SignupConstants.ActionTypes;\n\nconsole.log(ContactActionTypes.SEND_REQUEST === SignupActionTypes.SEND_REQUEST);\n// false\n```\n\n\n## License\n\nMIT\n\n\n## Don't forget\n\nWhat you create with `flux-constant` is more important than `flux-constant`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjedireza%2Fflux-constant","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjedireza%2Fflux-constant","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjedireza%2Fflux-constant/lists"}