{"action":"closed","issue":{"url":"https://api.github.com/repos/MatejMazur/react-schema-form/issues/4","repository_url":"https://api.github.com/repos/MatejMazur/react-schema-form","labels_url":"https://api.github.com/repos/MatejMazur/react-schema-form/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/MatejMazur/react-schema-form/issues/4/comments","events_url":"https://api.github.com/repos/MatejMazur/react-schema-form/issues/4/events","html_url":"https://github.com/MatejMazur/react-schema-form/issues/4","id":344869259,"node_id":"MDU6SXNzdWUzNDQ4NjkyNTk=","number":4,"title":"How should it look the API for the resolvers?","user":{"login":"MatejMazur","id":20944757,"node_id":"MDQ6VXNlcjIwOTQ0NzU3","avatar_url":"https://avatars2.githubusercontent.com/u/20944757?v=4","gravatar_id":"","url":"https://api.github.com/users/MatejMazur","html_url":"https://github.com/MatejMazur","followers_url":"https://api.github.com/users/MatejMazur/followers","following_url":"https://api.github.com/users/MatejMazur/following{/other_user}","gists_url":"https://api.github.com/users/MatejMazur/gists{/gist_id}","starred_url":"https://api.github.com/users/MatejMazur/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MatejMazur/subscriptions","organizations_url":"https://api.github.com/users/MatejMazur/orgs","repos_url":"https://api.github.com/users/MatejMazur/repos","events_url":"https://api.github.com/users/MatejMazur/events{/privacy}","received_events_url":"https://api.github.com/users/MatejMazur/received_events","type":"User","site_admin":false},"labels":[{"id":995149356,"node_id":"MDU6TGFiZWw5OTUxNDkzNTY=","url":"https://api.github.com/repos/MatejMazur/react-schema-form/labels/help%20wanted","name":"help wanted","color":"008672","default":true},{"id":995149359,"node_id":"MDU6TGFiZWw5OTUxNDkzNTk=","url":"https://api.github.com/repos/MatejMazur/react-schema-form/labels/question","name":"question","color":"d876e3","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/MatejMazur/react-schema-form/milestones/1","html_url":"https://github.com/MatejMazur/react-schema-form/milestone/1","labels_url":"https://api.github.com/repos/MatejMazur/react-schema-form/milestones/1/labels","id":3525464,"node_id":"MDk6TWlsZXN0b25lMzUyNTQ2NA==","number":1,"title":"v1.0.0","description":"","creator":{"login":"MatejMazur","id":20944757,"node_id":"MDQ6VXNlcjIwOTQ0NzU3","avatar_url":"https://avatars2.githubusercontent.com/u/20944757?v=4","gravatar_id":"","url":"https://api.github.com/users/MatejMazur","html_url":"https://github.com/MatejMazur","followers_url":"https://api.github.com/users/MatejMazur/followers","following_url":"https://api.github.com/users/MatejMazur/following{/other_user}","gists_url":"https://api.github.com/users/MatejMazur/gists{/gist_id}","starred_url":"https://api.github.com/users/MatejMazur/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MatejMazur/subscriptions","organizations_url":"https://api.github.com/users/MatejMazur/orgs","repos_url":"https://api.github.com/users/MatejMazur/repos","events_url":"https://api.github.com/users/MatejMazur/events{/privacy}","received_events_url":"https://api.github.com/users/MatejMazur/received_events","type":"User","site_admin":false},"open_issues":1,"closed_issues":2,"state":"open","created_at":"2018-07-26T14:15:26Z","updated_at":"2018-07-28T21:43:38Z","due_on":"2018-08-22T07:00:00Z","closed_at":null},"comments":1,"created_at":"2018-07-26T14:30:22Z","updated_at":"2018-07-28T21:43:38Z","closed_at":"2018-07-28T21:43:38Z","author_association":"OWNER","body":"The `props.resolvers` should solve the problem with derived values but at the same time it should be reusable outside of this lib so you can resolve derived values without React (e.g. on server side).\r\n\r\n```js\r\nimport { initResolve } from '@react-schema-form/core';\r\n\r\nconst schema = {\r\n  title: 'Calcs',\r\n  type: 'object',\r\n  properties: {\r\n    a: { type: 'number' },\r\n    b: { type: 'number' },\r\n    sum: {\r\n      type: 'number',\r\n      resolver: 'sum'\r\n    }\r\n  }\r\n};\r\n\r\nconst resolvers = {\r\n  sum: {\r\n    selectors: [values => values.a, values => values.b],\r\n    values: (a, b) => a + b\r\n  }\r\n};\r\n\r\nconst resolve = initResolve(resolvers, schema);\r\n\r\n// usage\r\nconst values = { a: 1, b: 2 };\r\nconsole.log(resolve(values)); // => { a: 1, b: 2, sum: 3 }\r\n```\r\n\r\n### API:\r\n\r\nResolvers are grouped inside of the `resolvers` object:\r\n\r\n```js\r\nconst resolvers = {\r\n  max: {\r\n    selectors: [values => values.a, values => values.b],\r\n    value: (a, b) => Math.max(a, b)\r\n  },\r\n  sum: {\r\n    selectors: [values => values.a, values => values.b],\r\n    value: (a, b) => a + b\r\n  },\r\n  resolverName: {\r\n    selectors: [(values, formProps) => value, ...],\r\n    value: (...selectors) => derivedValue\r\n  }\r\n};\r\n```\r\n\r\nThe resolver must contain one of these objects:\r\n\r\n1. `resolverName: { selectors, value }` (updates the derived value inside of the `values` object)\r\n1. `resolverName: { selectors, schema }` (extends the entity schema inside of the `schema` object)\r\n\r\n#### `resolverName` props:\r\n\r\n- `resolverName.selectors: ((values, formProps) => value)[]`\r\nThey should work the same way as selectors in Redux with Reselect but that means that I __need to solve the memoized selectors which are important for arrays items__.. how?\r\n\r\n- `resolverName.value: (...selectors: any[]) => newValue: any`\r\n- `resolver.schema: (...selectors: any[]) => schemaPart: object`"}}
{"actor":{"display_login":"MatejMazur"}}