{"id":21811465,"url":"https://github.com/dnbard/ecos","last_synced_at":"2025-03-21T09:15:15.052Z","repository":{"id":25951600,"uuid":"29393232","full_name":"dnbard/ecos","owner":"dnbard","description":"Entity Component System","archived":false,"fork":false,"pushed_at":"2015-01-22T09:58:44.000Z","size":212,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-19T21:06:38.407Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/dnbard.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":"2015-01-17T14:17:32.000Z","updated_at":"2020-11-23T21:57:19.000Z","dependencies_parsed_at":"2022-08-29T02:12:07.183Z","dependency_job_id":null,"html_url":"https://github.com/dnbard/ecos","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/dnbard%2Fecos","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnbard%2Fecos/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnbard%2Fecos/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnbard%2Fecos/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dnbard","download_url":"https://codeload.github.com/dnbard/ecos/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244767798,"owners_count":20507110,"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-27T13:44:46.801Z","updated_at":"2025-03-21T09:15:15.017Z","avatar_url":"https://github.com/dnbard.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"#Entity Component System\n\nSimple system to create and utilize objects in the right way.\n\n##Create objects\n```js\nvar factory = require('ecos').factory;\nvar entityFactory = factory.create({\n    props: ['x', 'y'],\n    name: 'my_entity'\n});\n\nvar entity = entityFactory.create();\nconsole.log(entity);\n{\n    x: undefined,\n    y: undefined,\n    id: 0,\n    type: 'my_entity'\n}\n```\n\n##Get objects\n```js\nvar objects = require('ecos').objects;\nvar entity = objects.get(0);\n\nconsole.log(entity);\n{\n    x: undefined,\n    y: undefined,\n    id: 0,\n    type: 'my_entity'\n}\n```\n\n##Ideas behind this library\n* Each entity is stored in unified container `ecos.objects` and accessible by its `id`\n* Entity should not have direct link to other entities. Parent entity store identificators of child entities instead\n* To get child entity just use `ecos.objects.get(childId);`\n* Since entities are stored only in one container then no memory leaks will occur when objects will be deleted\n* Different entities can share same `methods` and `extenders` and inherit same behaviour without prototype inheritance\n\n##Instalation\n\nAs `npm` package:\n```bash\nnpm install ecos --save\n```\n\nAs `bower` package:\n```bash\nbower install ecos --save\n```\n\n##Documentation\n\n###Factory\n\nTo create an entity first you need to create a `factory` that will produce entities:\n```js\nvar factory = require('ecos').factory;\nvar entityFactory = factory.create(options);\n```\n\n####Options:\n* **name** - factory identificator, *required* *string*\n* **props** - list of entity properties that will be initialized with `undefined`, *[ string ]*\n* **methods** - list of entity methods, all methods must be registered with `factory.registerMethod`, *[ string ]*\n* **extend** - list of extenders that will be applied to entity, all extenders must be registered with `factory.registerExtender`, *[ string ]*\n* **presets** - list of presets that will be applied to entity, all presets must be registered with `factory.registerPreset`. *[ string ]*\n* **default** - list of entity properties with predefined values, will overwrite `props` options, *{ propName: propValue }*\n* **custom** - list of entity properties with predefined values, will overwrite `props` and `default` options, is entity with this set will be accessible through `entityFactory.customEntity()` call, *{ customEntityName: { propName: propValue } }*\n\n####Create basic entity:\nWill create entity with fields.\n```js\nvar factory = require('ecos').factory;\nvar entityFactory = factory.create({\n    props: [ 'x', 'y' ],\n    name: 'example'\n});\nentityFactory.create();\n```\nResult:\n```\n{\n    type: 'example',\n    x: undefined,\n    y: undefined,\n    id: 0\n}\n```\n\nIf you pass object with fields to entity constructor then factory will create entity with specified fields defined:\n```js\nentityFactory.create({x: 100, y: 200});\n```\nResult:\n```\n{\n    type: 'example',\n    x: 100,\n    y: 200,\n    id: 0\n}\n```\n\n####Create entity with method:\nUse `factory.registerMethod` to register method that can be assigned to entity:\n```js\nfactory.registerMethod('console', function(text){\n    console.log(text);\n});\n\nvar entityFactory = factory.create({\n    methods: ['console'],\n    name: 'example'\n});\nentityFactory.create();\n```\nResult:\n```\n{\n    type: 'example',\n    console: function\n    id: 0\n}\n```\n\n####Create entity with GETSET extender:\nThis extender will create field with defined getter and setter.\n\n```js\nvar extenders = require('ecos').extenders;\n\nfactory.registerExtender('value-extender', {\n    get: function(){\n        return this._value;\n    },\n    set: function(val){\n        this._value = val;\n        console.log('Value set to ' + val);\n    },\n    name: 'value',\n    type: extenders.GETSET\n});\n\nvar entityFactory = factory.create({\n    extend: ['value-extender'],\n    name: 'example'\n});\n\nentityFactory.create();\nentity.value = Math.random();\n```\nResult:\n```\nValue set to 0.758898114\n```\nIf you wont specify `get` or `set` function in extender definition then resulting field wont have getter or setter defined.\n\n####Create entity with FUNCTION extender:\nThis extender will run custom function on object creation.\n\n```js\nfactory.registerExtender('function-extender', {\n    type: extenders.FUNCTION,\n    handler: function(thisObject){\n        console.log('Creating ' + JSON.stringify(thisObject));\n    }\n});\n\nvar entityFactory = factory.create({\n    extend: ['function-extender'],\n    name: 'example'\n});\n\nentityFactory.create();\n```\nResult:\n```\nCreating {\"type\":\"example\", \"id\":0}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdnbard%2Fecos","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdnbard%2Fecos","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdnbard%2Fecos/lists"}