{"id":18799615,"url":"https://github.com/l2silver/erschema-suite","last_synced_at":"2026-01-02T20:30:16.758Z","repository":{"id":97819316,"uuid":"95275658","full_name":"l2silver/erschema-suite","owner":"l2silver","description":null,"archived":false,"fork":false,"pushed_at":"2017-09-26T12:55:40.000Z","size":35,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-29T18:34:56.474Z","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-24T04:28:44.000Z","updated_at":"2017-06-24T04:29:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"7ed2598c-71ae-4afd-9efd-cb06061837ff","html_url":"https://github.com/l2silver/erschema-suite","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%2Ferschema-suite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/l2silver%2Ferschema-suite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/l2silver%2Ferschema-suite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/l2silver%2Ferschema-suite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/l2silver","download_url":"https://codeload.github.com/l2silver/erschema-suite/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239727900,"owners_count":19687267,"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:55.024Z","updated_at":"2026-01-02T20:30:16.684Z","avatar_url":"https://github.com/l2silver.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# erschema-suite\n\nA smart immutablejs library for managing and accessing the redux-store\n\n### Basic Concepts\n\nRedux applications all have a few key components. Reducers to change the store's state, actions to trigger the reducer, and selectors to pull data from the store.\nMost applications will write a custom function for each case in a reducer function, which generally require custom actions to trigger the reducer, and custom selectors to retreive the data.\nErschema-suite uses standard RESTful reducers and actions, which also results in a standardized store state that is easy to select data from.\n\n### Redux Store\n\nThe erschema provides a reducer function that stores data in two basic places: Entities, and Relationships.\n\n```\nimport {Record, Map} from 'immutable'\n// Example redux store with erschema\n{\n  other store properties...,\n  erschema: {\n    entities: Map\u003c{\n      users: Record\u003c{\n        data: Map\u003c{\n          id: UserRecord\u003c{id, name}\u003e\n        }\u003e\n      }\u003e\n    }\u003e,\n    relationships: Map\u003c{\n      users: Map\u003c{\n        friends: Map\u003c{\n          [userId]: OrderedList\u003cfriendId\u003e (For one to many relationships) || friendId (for one to one relationships)\n        }\u003e\n      }\u003e\n    }\u003e\n  }\n}\n```\n\n#### Schemas\n\nErschema uses a modified and flat version of https://github.com/paularmstrong/normalizr to not only normalize data, but also construct the structure of the redux-store\n\n```\nimport {combineReducers} from 'redux'\nimport erschemaReducer from 'erschema-suite/reducer'\n\nconst usersSchema = {\n  idFunc: (entity)=\u003eentity.id,\n  properties: {id: 0, name: ''},\n  modifier: (ent)=\u003eent,\n  Model: UserModel,\n  relationships: {\n    manyRelationships: {\n      friends: [\n        {\n          name: 'users',\n        }\n      ]\n    },\n    monoRelationships: {}\n  },\n}\n\ncombineReducers({\n  ...otherReducers,\n  erschemaReducer({\n    schemas: {\n      users,\n    }\n  })\n})\n\n===\u003e creates a redux store with the following structure\n\n{\n  ...otherReducers,\n  erschema: {\n    entities: Map\u003c{\n      users: Map\u003c{\n        data: Map\u003c{}\u003e\n      }\u003e\n    }\u003e,\n    relationships: Map\u003c{\n      users: Map\u003c{\n        friends: Map\u003c{}\u003e\n      }\u003e\n    }\u003e\n  }\n}\n\n```\n\n\n### Actions\n\n#### The standardize erschema actions for relationships are:\n\n* link\n* unlink\n* createRelationship\n* indexRelationship\n* concatRelationship\n* reorder\n\n##### link\n\nAdds a relatedEntityId to a relationship for one-to-many relationships, or for one-to-one relationship, changes relatedEntityId value\n\n```\n// Relationship change for links one-to-many and one-to-one respectively\n{\n  [entityId]: [] ===\u003e [relatedEntityId] || 0 ===\u003e relatedEntityId \n}\n```\n\n##### unlink\n\nRemoves a relatedEntityId from a relationship for one-to-many relationships, or for one-to-one relationship, changes relatedEntityId value to 0\n\n```\n// Relationship change for links one-to-many and one-to-one respectively\n{\n  [entityId]: [relatedEntityId] ===\u003e [] || relatedEntityId ===\u003e 0\n}\n```\n\n##### createRelationship\n\nCreates a relationship entry for an entityId\n```\n// Relationship created for links one-to-many and one-to-one respectively\n{} ===\u003e {\n        [entityId]: [relatedEntityId] || relatedEntityId \n      }\n```\n\n##### indexRelationship\n\nCreates a relationship entry for multiple entity ids\n```\n// Relationship created for links one-to-many and one-to-one respectively\n{} ===\u003e {\n        [entityId]: [relatedEntityId] || relatedEntityId ,\n        [entityId2]: [relatedEntityId2] || relatedEntityId2 ,\n        [entityId3]: [relatedEntityId3] || relatedEntityId3 \n      }\n```\n\n##### concatRelationship\n\nAdds multiple relatedEntityIds to an existing relationship for multiple\n```\n{\n  [entityId]: [relatedEntityId] ===\u003e [relatedEntityId, relatedEntityId2, relatedEntityId3]\n}\n```\n\n##### reorder\n\nReorders relationship\n```\n{\n  [entityId]: [relatedEntityId, relatedEntityId2, relatedEntityId3] ===\u003e [relatedEntityId2, relatedEntityId, relatedEntityId3]\n}\n```\n\n#### The standardized erschema actions for entities are:\n\n* create\n* update\n* remove\n* get\n* index\n\n##### create\n\ncreates an entity\n```\n{\n  data: {} ===\u003e {\n                  [entityId]: entity \n                }\n}\n```\n\n##### update\n\nupdates an entity\n```\n{\n  data: {\n   [entityId]: entity ===\u003e entity2\n  }\n}\n```\n\n##### remove\n\nremoves an entity\n```\n{\n  data: {[entityId]: entity} ===\u003e {}\n}\n```\n\n##### get/index\n\ngets for adding a single entity, or index for adding multiple entities of the same type.\n\nget and index are also special because these are the actions that do normalizing. So anytime you get an object, and it has nested entities in it, you must use either get or index to store the normalized data properly in the reducer\n\n#### The Action Class\n\nInstead of calling the actions individually when ever they're needed, erschema-suite comes with an Actions class that stores the basic entity actions in the actions property of the class\n\n```\n// Using the get action stored in the Actions class\nconst USERS = 'users'\n\nclass UserActions extends Actions {\n  get = (id: number) =\u003e dispatch =\u003e {\n    return userService.get(id).then((user)=\u003e{\n      dispatch(this.actions.get(user))\n    })\n  }\n}\nexport default new UserActions(USERS)\n```\n\n### Selectors\n\nSelectors are a way of minimizing rerender cycles in react. See https://github.com/reactjs/reselect for more information\n\nErschema ships with a Selectors class that comes with a basic set of selectors that can be used to access any part of the redux store, and they are as follows:\n\n* findEntity\n* getEntities\n* getRelatedEntityIds\n* getRelatedEntityId\n* findEntityData\n* findManyRelationshipData\n* findMonoRelationshipData\n\n#### findEntity\n\nRetrieve a single entity\n\n```\n// default idSelector is props.id\nthis.findEntity(idSelector?: (state, props)=\u003eid = (state, props)=\u003eprops.id)\n```\n\n#### getEntities\n\nRetrieves many entities\n\n```\nthis.getEntity(idsSelector: (state, props)=\u003e[id])\n```\n\n#### findRelatedEntityId\n\nRetrieve related entity id for one-to-one relationship\n\n```\nthis.findRelatedEntityId(relationshipName: string, idSelector?: (state, props)=\u003eid = (s,p)=\u003ep.id)\n```\n\n#### getRelatedEntityIds\n\nRetrieve related entity id for one-to-one relationship\n\n```\nthis.getRelatedEntityIds(relationshipName: string, idSelector?: (state, props)=\u003eid = (s,p)=\u003ep.id)\n```\n\n#### findEntityData, findMonoRelationshipData, findManyRelationshipData\n\nGet all of the respective entities, monoRelationships, and manyRelationships\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fl2silver%2Ferschema-suite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fl2silver%2Ferschema-suite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fl2silver%2Ferschema-suite/lists"}