Comments (6)
Where does this toObject
convention come from?
from orderedmap.
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.
Sorry, that doesn't sound like a very compelling reason. You'll have other issues with ProseMirror when loading libraries multiple times.
from orderedmap.
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.
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.
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)
- [feature request] a way to break `forEach` - or add `some` ? HOT 1
- Use named export for ES module compatibility HOT 1
- can not use namespace 'OrderedMap' as a type. HOT 4
- Error with TypeScript 3.5, "An accessor cannot be declared in an ambient context." HOT 2
- The type definition does not match the source code HOT 3
- Any plans for implementing Symbol.iterator support? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from orderedmap.