npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

y-array2

v1.5.0

Published

Array Type for Yjs

Downloads

5

Readme

Array Type for Yjs

This plugins provides a shareable Array type. You can insert and delete objects in y-array. The objects must either be a custom type, or fulfill the following property: v equals JSON.parse(JSON.stringify(v)) (according to your definition of equality)

Use it!

Install this with bower or npm.

Bower
bower install y-array --save
NPM
npm install y-array --save

Array Object

Reference
  • .insert(position, contents)
    • Insert an array of content at a position
    • You can also insert types array.insert(0, Y.Map)
    • 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)
  • .push(content)
    • Insert content at the end of the Array
    • Also see .insert(..)
  • .delete(position, length)
    • Delete content. The length parameter is optional and defaults to 1
  • .toArray()
    • Retrieve the complete content as an array
  • .get(position)
    • Retrieve content from a position
  • .observe(function observer(event){..})
    • The observer is called whenever something on this array changes
    • Throws insert, and delete events (event.type)
    • Insert event example: {type: 'insert', index: 0, values: [0, 1, 2], length: 3}
    • Delete event example: {type: 'delete', index: 0, oldValues: [0, 1, 2], length: 3}
  • .observeDeep(function observer(event){..})
    • Same as .observe, but catches events from all children (if they support .observeDeep)
    • event.path specifies the path of the change event
  • .unobserve(f)
    • Delete an observer

A note on intention preservation

If 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.

A note on time complexities

  • .insert(position, content)
    • O(contents.length)
  • .push(content)
    • O(1)
  • .delete(position, length)
    • O(position + length)
  • .get(i)
    • O(length)
  • Apply a delete operation from another user
    • O(contents.length)
  • Apply an insert operation from another user
    • Yjs does not transform against operations that do not conflict with each other.
    • An operation conflicts with another operation if it intends to be inserted at the same position.
    • Overall worst case complexety: O(|conflicts|^2)

Changelog

10.0.0

  • Inserting & retrieving types are synchronous operations
    • I.e. `y.share.array.get(0) // => returns a type instead of a promise (if there is a type at position 0)
  • Relies on Yjs@^12.0.0

License

Yjs is licensed under the MIT License.

[email protected]