{"id":24379692,"url":"https://github.com/y-js/y-array","last_synced_at":"2025-04-10T21:09:56.251Z","repository":{"id":57402634,"uuid":"45755397","full_name":"y-js/y-array","owner":"y-js","description":"Array type for Yjs","archived":false,"fork":false,"pushed_at":"2017-10-06T21:50:46.000Z","size":1646,"stargazers_count":13,"open_issues_count":2,"forks_count":6,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-28T17:44:19.832Z","etag":null,"topics":["yjs","yjs-type"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/y-js.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":"2015-11-07T21:28:20.000Z","updated_at":"2023-12-28T17:32:38.000Z","dependencies_parsed_at":"2022-09-11T05:01:42.502Z","dependency_job_id":null,"html_url":"https://github.com/y-js/y-array","commit_stats":null,"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/y-js%2Fy-array","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/y-js%2Fy-array/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/y-js%2Fy-array/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/y-js%2Fy-array/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/y-js","download_url":"https://codeload.github.com/y-js/y-array/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247834139,"owners_count":21003912,"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":["yjs","yjs-type"],"created_at":"2025-01-19T07:18:46.869Z","updated_at":"2025-04-10T21:09:56.227Z","avatar_url":"https://github.com/y-js.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Array Type for [Yjs](https://github.com/y-js/yjs)\n\nThis plugins provides a shareable Array type. You can insert and delete objects in y-array. The objects must either be a custom type,\nor fulfill the following property: `v equals JSON.parse(JSON.stringify(v))` (according to your definition of equality)\n\n## Use it!\nInstall this with bower or npm.\n\n##### Bower\n```\nbower install y-array --save\n```\n\n##### NPM\n```\nnpm install y-array --save\n```\n\n### Array Object\n\n##### Reference\n\n* .insert(position, contents)\n  * Insert an array of content at a position\n  * You can also insert types `array.insert(0, Y.Map)`\n  * If not a shared type, the content should fulfill the following property: `content equals JSON.parse(JSON.stringify(content))` (according to your notion of equality)\n* .push(content)\n  * Insert content at the end of the Array\n  * Also see `.insert(..)`\n* .delete(position, length)\n  * Delete content. The *length* parameter is optional and defaults to 1\n* .toArray()\n  * Retrieve the complete content as an array\n* .get(position)\n  * Retrieve content from a position\n* .observe(function observer(event){..})\n  * The `observer` is called whenever something on this array changes\n  * Throws insert, and delete events (`event.type`)\n  * Insert event example: `{type: 'insert', index: 0, values: [0, 1, 2], length: 3}`\n  * Delete event example: `{type: 'delete', index: 0, oldValues: [0, 1, 2], length: 3}`\n* .observeDeep(function observer(event){..})\n  * Same as .observe, but catches events from all children (if they support .observeDeep)\n  * `event.path` specifies the path of the change event\n* .unobserve(f)\n  * Delete an observer\n\n\n# A note on intention preservation\nIf two users insert something at the same position concurrently, the content that was inserted by the user with the higher user-id will be to the right of the other content. In the OT world we often speak of *intention preservation*, which is very loosely defined in most cases. This type has the following notion of intention preservation: When a user inserts content *c* after a set of content *C_left*, and before a set of content *C_right*, then *C_left* will be always to the left of c, and *C_right* will be always to the right of *c*. Since content is only marked as deleted (until all conflicts are resolved), this notion of intention preservation is very strong.\n\n# A note on time complexities\n* .insert(position, content)\n  * O(contents.length)\n* .push(content)\n  * O(1)\n* .delete(position, length)\n  * O(position + length)\n* .get(i)\n  * O(length)\n* Apply a delete operation from another user\n  * O(contents.length)\n* Apply an insert operation from another user\n  * Yjs does not transform against operations that do not conflict with each other.\n  * An operation conflicts with another operation if it intends to be inserted at the same position.\n  * Overall worst case complexety: O(|conflicts|^2)\n\n## Changelog\n\n### 10.0.0\n* Inserting \u0026 retrieving types are synchronous operations\n  * I.e. `y.share.array.get(0) // =\u003e returns a type instead of a promise (if there is a type at position 0)\n* Relies on Yjs@^12.0.0\n\n## License\nYjs is licensed under the [MIT License](./LICENSE).\n\n\u003ckevin.jahns@rwth-aachen.de\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fy-js%2Fy-array","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fy-js%2Fy-array","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fy-js%2Fy-array/lists"}