Coder Social home page Coder Social logo

Comments (6)

marijnh avatar marijnh commented on June 5, 2024

Where does this toObject convention come from?

from orderedmap.

Tezraine avatar Tezraine commented on June 5, 2024

I would say it's an implied convention. Generally, "Object" refers to an unstructured data blob, and the existence of a 0 argument toObject function implies that this thing has a proper "Object" form, but it's current form is not it. I can't think of any situation where an object has a 0 arg toObject function, and it's current form would be useful in the OrderedMap.

For example, compatibility with this library could be achieved toObject() method - Collections for JavaScript (collectionsjs.com) if you checked for this behavior for compatibility.

Also basing my thoughts on how Promise libraries generally identify something as a promise. InstanceOf is not a reliable way of checking for a behavior, because different copies/implementations will return false even though they are still compatible.

On a side note, my use case actually stems from starting to learn Prosemirror. This change would not fix the the "double import of prosemirror-model", but it would reduce the severity enough for the doc to still render in read only mode. So I get a "you might have more then one prosemirror-model" error instead of a "missing doc topNode" error. And I would not need to flag orderedmap as a force-share library.

from orderedmap.

marijnh avatar marijnh commented on June 5, 2024

Sorry, that doesn't sound like a very compelling reason. You'll have other issues with ProseMirror when loading libraries multiple times.

from orderedmap.

Tezraine avatar Tezraine commented on June 5, 2024

The Prosemirror case was just a side note of another library that would get a usability benefit from this change. My main issue is that the from function states If given an ordered map, return that map itself. However, thanks to the subtleties of instanceof and modules and instantiation, under less then perfect circumstances, you will get an ordered map of the the orderedmap instead of getting that orderedmap back because instanceof only returns true if it was created with that specific prototype instance.

I consider that a bug, but the toObject feature would fix that bug in a type safe way, as well as add compatibility with other collections with toObject functions, not just the very specific instance it was created from.

If you like, I can create a separate issue for specifically discussing that bug of instanceOf returning false after an orderedmap instance is cloned.

from orderedmap.

marijnh avatar marijnh commented on June 5, 2024

If you like, I can create a separate issue for specifically discussing that bug of instanceOf returning false after an orderedmap instance is cloned.

I don't know how you're cloning the instance, but if you use OrderedMap.from then instanceof will continue to return true.

from orderedmap.

Tezraine avatar Tezraine commented on June 5, 2024

I don't know where the clone is coming from. The package-lock only lists 1 orderedmap installed, but instanceof is still returning false. I think one of the commonjs packages I have installed bundled it's own copy of orderedmap into itself, which instanceof returns false against causing everything to die horribly. And grep gets too many results. Right now my only solution looks like starting over from scratch and implementing all the plugins and header myself. (Maybe start over from TipTap)

from orderedmap.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.