{"id":26202234,"url":"https://github.com/astef/model-events","last_synced_at":"2025-07-17T14:35:28.544Z","repository":{"id":57749644,"uuid":"524727995","full_name":"astef/model-events","owner":"astef","description":"Receive events from your model field changes.","archived":false,"fork":false,"pushed_at":"2022-08-27T23:20:43.000Z","size":67,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-17T16:55:37.236Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/astef.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":"2022-08-14T16:49:11.000Z","updated_at":"2022-12-01T21:19:30.000Z","dependencies_parsed_at":"2022-08-28T08:52:42.142Z","dependency_job_id":null,"html_url":"https://github.com/astef/model-events","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/astef/model-events","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astef%2Fmodel-events","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astef%2Fmodel-events/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astef%2Fmodel-events/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astef%2Fmodel-events/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/astef","download_url":"https://codeload.github.com/astef/model-events/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/astef%2Fmodel-events/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265617338,"owners_count":23799025,"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":"2025-03-12T03:33:55.561Z","updated_at":"2025-07-17T14:35:28.525Z","avatar_url":"https://github.com/astef.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# model-events\n\n\u003cspan\u003e\u003ca href=\"https://npmjs.org/package/model-events\" title=\"View this project on NPM\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/model-events.svg\" alt=\"NPM version\" /\u003e\u003c/a\u003e\u003c/span\u003e\n\nTypeScript-first zero-dependency package to generate events from your model field changes.\n\n## Installation\n\n`npm install model-events`\n\n## Example\n\n```typescript\nimport { defineModel, defineObject, defineField, Infer } from \"model-events\";\n\n// define your schema just as you define types\nconst modelSchema = defineModel(\n  {\n    player1: defineObject({\n      score: defineField(0),\n    }),\n    player2: defineObject({\n      score: defineField(0),\n    }),\n  },\n  {\n    name: defineField(\"Round 1\"),\n  }\n);\n\n// and infer your actual type later\ntype TwoPlayerGameModel = Infer\u003ctypeof modelSchema\u003e;\n\n// create an instance with default field values\nconst model: TwoPlayerGameModel = modelSchema.create();\n\n// subscribe to field updates\nmodel.on(\"value\", (field, value) =\u003e {\n  // field index is unique within the entire model\n  console.log(`[${field.index}]=${value}`);\n});\n\n// and finally do your computations!\nfunction play(model: TwoPlayerGameModel) {\n  for (let i = 1; i \u003c= 10; i++) {\n    model.player1.score += 33 % i;\n    model.player2.score += model.player1.score % 5;\n  }\n}\n\nplay(model);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fastef%2Fmodel-events","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fastef%2Fmodel-events","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fastef%2Fmodel-events/lists"}