{"id":20145742,"url":"https://github.com/obsius/tbjson-handler","last_synced_at":"2025-10-13T00:24:37.484Z","repository":{"id":65514917,"uuid":"241292517","full_name":"obsius/tbjson-handler","owner":"obsius","description":"An event handler for tbjson annotated data.","archived":false,"fork":false,"pushed_at":"2022-09-06T22:56:05.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-13T00:24:36.824Z","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/obsius.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":"2020-02-18T06:51:22.000Z","updated_at":"2021-12-18T02:19:51.000Z","dependencies_parsed_at":"2023-01-26T21:15:18.685Z","dependency_job_id":null,"html_url":"https://github.com/obsius/tbjson-handler","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/obsius/tbjson-handler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obsius%2Ftbjson-handler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obsius%2Ftbjson-handler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obsius%2Ftbjson-handler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obsius%2Ftbjson-handler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/obsius","download_url":"https://codeload.github.com/obsius/tbjson-handler/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/obsius%2Ftbjson-handler/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279013634,"owners_count":26085298,"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","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"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-13T22:17:57.560Z","updated_at":"2025-10-13T00:24:37.447Z","avatar_url":"https://github.com/obsius.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TBJSON Handler\n\nAn event handler based off of the standard DOM event chain, but for TBJSON annotated data.\n  \n[Read about TBJSON here.](https://www.npmjs.com/package/typed-binary-json)\n\n## Format\n\nTyped Binary JSON provides a way to describe structured data.  \nThis package follows the TBJSON scheme and provides a way to listen to events (changes) in the structured data.  \nThe typical use case for this package is needing to listen for a change in a complicated tree structure while being performance minded.  \nAll of your classes must derive from the Handler Class.  \nIt is best to have a base `Model` class that inherits from `TbjsonHandler` so that you can add common functionality there.\n\n### Working Example\n\n```js\n\nimport Tbjson from 'typed-binary-json';\nimport Handler from 'tbjson-handler';\n\nclass Model extends Handler {\n\n\t// a modelType accessor must be present on all classes\n\t// modelType will be propagated up to allow for selective listening\n\tget modelType() {\n\t\treturn this.constructor.modelType;\n\t}\n}\n\nModel.modelType = 'Model'; // set the value of the protype itself, the getter will source from here\n\nclass A extends Model {\n\n\t@Handler.prop x = 'string'; // handle when x changes\n\t@Handler.prop y = 'boolean'; // handle when y changes\n\tz = [new A(), new A()]\n\n\t// handle when this function is called\n\t@Handler.handle addZ(z) {\n\t\tthis.z.push(z);\n\t}\n}\n\nA.modelType = 'A';\n\nA.tbjson = {\n\n\t// by default all properties in the definition below are listened to, set a property to false here to omit one\n\thandles: {\n\t\tz: false // do not listen to z\n\t},\n\n\t// the TBJSON definition\n\tdefinition: {\n\t\tx: Tbjson.TYPES.STRING, // a string\n\t\ty: Tbjson.TYPES.STRING, // a string\n\t\tz: [Tbjson.TYPES.ARRAY, A] // an array of class A\n\t}\n};\n\nclass B extends Model {\n\ta = new A();\n}\n\nB.modelType = 'B';\n\nB.tbjson = {\n\tdefinition: {\n\t\ta: A // a is of class A (above)\n\t}\n};\n\nclass C extends Model {\n\tb = new B();\n}\n\nC.modelType = 'C';\n\nC.tbjson = {\n\tdefinition: {\n\t\tb: B // b is of class B (above)\n\t}\n};\n\nlet c = new C();\n\nc.listen(null, null, (e) =\u003e console.log(e)); // listen for any event\n\nc.b.a.addZ(new A()); // console will print a TbjsonHandlerEvent (below)\n\n// TbjsonHandlerEvent: {\n//     obj: c,\n//     path: ['A', 'B', 'C'],\n//     objs: [a, b, c],\n//     type: undefined,\n//     property: undefined,\n//     value: undefined\n// }\n\n```\n\n## Methods\n\nAll classes that inherit from `TbjsonHandler` (the default and only export of this package) will have the following methods:\n\n### inject(parentHandler) =\u003e undefined\n\nInject a handler into the object (will crawl all TBJSON defined properties and also add to those).\n\n### handle(e, local) =\u003e undefined\n\nFire an event. If nothing is passed a new `TbjsonHandlerEvent` will be made for the class.\nIf you've already constructed an event for this class, pass true as arg 2, and the class will not re-add its signature.\n\n### listen(nameOrArrayOrFilterFn, propertyNameOrArray, fn) =\u003e destroyer()\n\nAttach a listener to an object.\n\nTakes in:\n\n- arg 1: a `modelType` (class name), or array of them, or a filter function\n- arg 2: a property name or array of them\n- arg 3: the function to call if an event matches\n\n## Decorators\n\nUse these decorators to control how events will be handled.\n\n### @Handler.inject\n\nFire an event everytime this function is called and also inject `this` into the first argument passed into the function (`inject()` will be called on the passed object).\n\n### @Handler.injectType(type, objArgIndex)\n\nSame as above but also provide a type (string) and optionally an argument number as to which argument needs injection.\nType will be a field on the event object that bubbled up.\n\n### @Handler.handle\n\nFire an event everytime this function is called.\n\n### @Handler.handleType(type)\n\nFire an event everytime this function is called and include a type to be addded to the event object that will bubble up.\n\n### @Handler.prop\n\nFire an event everytime the property changes. An event type of `changed` will always be set on the propogating event.\n\n## Visible Data\n\nThe only data that will be passed up will be of `TbjsonHandlerEvent`.\n\n```js\nTbjsonHandlerEvent {\n\tobj: {}, // the source object\n\tpath: [], // an array of string which are the modelTypes (class names)\n\tobj: [], // the actual objects that correspond to the path above\n\ttype: 'string', // the type of event\n\tproperty: 'string', // if a property has changed, the property name\n\tvalue: 'any', // if a property has changed, the new property value\n}\n```\n\n## Contributing\n\nFeel free to make changes and submit pull requests whenever.\n\n## License\n\nTBJSON Handler uses the [MIT](https://opensource.org/licenses/MIT) license.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fobsius%2Ftbjson-handler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fobsius%2Ftbjson-handler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fobsius%2Ftbjson-handler/lists"}