{"id":18799573,"url":"https://github.com/l2silver/normer-actions","last_synced_at":"2026-01-02T20:30:16.173Z","repository":{"id":57312075,"uuid":"122252902","full_name":"l2silver/normer-actions","owner":"l2silver","description":null,"archived":false,"fork":false,"pushed_at":"2018-02-21T04:33:36.000Z","size":54,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-30T03:45:23.160Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/l2silver.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}},"created_at":"2018-02-20T20:35:24.000Z","updated_at":"2018-02-21T14:09:34.000Z","dependencies_parsed_at":"2022-09-16T02:51:28.397Z","dependency_job_id":null,"html_url":"https://github.com/l2silver/normer-actions","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/l2silver%2Fnormer-actions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/l2silver%2Fnormer-actions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/l2silver%2Fnormer-actions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/l2silver%2Fnormer-actions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/l2silver","download_url":"https://codeload.github.com/l2silver/normer-actions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239727755,"owners_count":19687242,"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-07T22:15:46.966Z","updated_at":"2026-01-02T20:30:14.094Z","avatar_url":"https://github.com/l2silver.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# normer-actions\n\n[![Build Status](https://travis-ci.org/l2silver/normer-actions.svg?branch=master)](https://travis-ci.org/l2silver/normer-actions)\n\nA plugin that generates entity and relationship actions based on the normalized output of the normer plugin.\n\n## Setup\n\n```npm install normer normer-actions --save```\n\n## Usage\n\n```\nimport { relationshipTypes } from 'normer'\nimport createNormerActionsCreator from 'normer-actions'\n\nconst entityActionsCreatorGenerator = (entityName: string, id: string | number)=\u003e{\n  get: (entity)=\u003e({\n    type: `${entityName}/get`,\n    payload: entity,\n  }),\n  ...\n}\n\nconst relationshipActionsCreatorGenerator = (entityName: string, relationshipName: string, id: string | number)=\u003e{\n  create: (value)=\u003e({\n    type: `${entityName}/${relationshipName}/create`,\n    payload: {id, value},\n  }),\n  ...\n}\n\nconst normerSchema = {\n  users: {\n    modifier: ({friends, ...props})=\u003eprops,\n    relationships: [{\n      entityName: 'users',\n      name: 'friends',\n      type: relationshipTypes.MANY,\n    }]\n  }\n}\n\nconst normerActionsCreator = createNormerActionsCreator(\n  entityActionsCreatorGenerator,\n  relationshipActionsCreatorGenerator,\n  normerSchema\n);\n\nconst input = {\n  id: 1,\n  name: 'Loyd',\n  friends: [{\n    id: 2,\n    name: 'Harry'\n  }]\n}\n\nconst normerActions = normerActionsCreator(input, 'users')\n\nconsole.log(normerActions)\n/*\n[\n  {\n    type: 'users/get',\n    payload: {\n      id: 1,\n      name: 'Loyd',\n    }\n  },\n  {\n    type: 'users/get',\n    payload: {\n      id: 2,\n      name: 'Harry',\n    }\n  },\n  {\n    type: 'users/friends/create',\n    payload: {\n      id: 1,\n      value: [2],\n    }\n  },\n]\n*/\n\n```\n\n## Why is this necessary\n\nThere are a lot of normalizers on npm, and they all normalize very well, most particularly, normalizr. The trick is how to use that normalized data. For many redux users, as far as I know, this requires a custom approach. I wanted to abstract away some of that customization, but at the same time, leave the plugin open to almost any configuration.\n\n## How it works\n\nThe basic idea is that normer-actions process a deeply nested object using the normer library's normalizing capabilities, and then parse the results into easy to use actions. The normer-actions library creates these actions through separate entity and relationship action creators. Action creators generator =\u003e action creators =\u003e actions. An action creator generator will return an object of action creator functions.\n\nEntity action creator object\n```\n{\n  get: (ent)=\u003e({...}),\n  ...\n}\n```\n\nRelationship action creator object\n```\n{\n  create: ({id, value})=\u003e({...}),\n  ...\n}\n```\n\nThe get action creator and create action creator are the default creators for the respective entity and relationship action creators.\n\n## Advanced Features: Options\n\nThe third argument of the normerActionsCreator (ie. the resulting function when calling the createNormerActionsCreator) is an options object with the following properties:\n\n```\nentityActionsCreator(input, entityName, options)\n```\n\n### startingSchema\n\n```\nconst options = {\n  startingSchema: {\n    idFunc: ()=\u003e'pages'\n  }\n}\n```\n\nThe starting schema is a normer concept, and it allows you to pass in the exact starting schema to be used when parsing a deeply nested object. Once the object goes through the first parse, it reverts back to using the regular schema for the remainder parsings.\n\n### entity\n\n```\nconst options = {\n  entity: (entityName, id)=\u003e{\n    actionName: 'create'\n  }\n}\n```\n\nA function that takes the current entityName and id and returns an object. Currently, there is only one option, actionName, which allows you to change which actionCreator is called.\n\n### relationship\n\n```\nconst options = {\n  relationship: (entityName, relationshipName, id)=\u003e{\n    actionName: 'create'\n  }\n}\n```\n\nA function that takes the current entityName, relationshipName and id and returns an object. Currently, there is only one option, actionName, which allows you to change which actionCreator is called.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fl2silver%2Fnormer-actions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fl2silver%2Fnormer-actions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fl2silver%2Fnormer-actions/lists"}