{"id":20182133,"url":"https://github.com/nichoth/model","last_synced_at":"2026-06-17T23:31:36.171Z","repository":{"id":77400113,"uuid":"79855371","full_name":"nichoth/model","owner":"nichoth","description":"Functions for modeling application state","archived":false,"fork":false,"pushed_at":"2017-01-23T22:34:18.000Z","size":5,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-10T06:37:34.217Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/tvwit/model#readme","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/nichoth.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-01-23T22:34:10.000Z","updated_at":"2017-01-24T03:14:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"4610edac-99b2-4fb0-9870-622670b5266a","html_url":"https://github.com/nichoth/model","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nichoth/model","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nichoth%2Fmodel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nichoth%2Fmodel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nichoth%2Fmodel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nichoth%2Fmodel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nichoth","download_url":"https://codeload.github.com/nichoth/model/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nichoth%2Fmodel/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34470322,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-17T02:00:05.408Z","response_time":127,"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":[],"created_at":"2024-11-14T02:37:45.551Z","updated_at":"2026-06-17T23:31:36.155Z","avatar_url":"https://github.com/nichoth.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# model\n\nFunctions for reducing a log of events into application state.\n\n## Api\n\n`index.js` consumes the folowing events\n\n```js\n[\n    'start',\n    'resolve',\n    'pushError',\n    'shiftError',\n    'get',\n    'edit',\n    'add',\n    'delete'\n];\n```\n\n## example\n\n```js\nvar test = require('tape');\nvar Model = require('../');\n\ntest('compose models', function (t) {\n    t.plan(1);\n    var TestModel = Model('id');\n    var evs = [\n        ['start', { op: 'get' }],\n        ['get', [{ id: 'a' }]],\n        ['resolve', { op: 'get' }],\n        ['pushError', { test: 'test' }]\n    ];\n\n    var states = evs.reduce(function (acc, ev) {\n        var type = ev[0];\n        var fn = TestModel.update[type];\n        var state = fn(acc[acc.length - 1], ev[1]);\n        return acc.concat(state);\n    }, [TestModel()]);\n\n    t.deepEqual(states, [{\n        resolving: [],\n        errors: [],\n        data: {}\n    }, {\n        resolving: [{ op: 'get' }],\n        errors: [],\n        data: {}\n    }, {\n        resolving: [{ op: 'get' }],\n        errors: [],\n        data: { a: { id: 'a' } }\n    }, {\n        resolving: [],\n        errors: [],\n        data: { a: { id: 'a' } }\n    }, {\n        resolving: [],\n        errors: [{ test: 'test' }],\n        data: { a: { id: 'a' } }\n    }], 'should compose reduce functions');\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnichoth%2Fmodel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnichoth%2Fmodel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnichoth%2Fmodel/lists"}