-
-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Idea: Only treat objects without prototypes as StrMaps #704
Comments
This definitely need a But please make it simple to convert a foreign object to a |
I like this idea! How would we describe the type of the data constructor? StrMap :: ??? -> StrMap a Would |
I vote for a way to convert all properties to String but You often get a foreign object such as: {
fill: '#f06'
, 'fill-opacity': 0.5
, stroke: '#000'
, 'stroke-width': 10
} |
@dotnetCarpenter, are you suggesting that the data constructor's return type should be |
It might be fine just to have it return a mixed-type StrMap. It's possible to work with mixed-type StrMaps outside of Sanctuary, or using |
It's just like the Array constructor; We allow users to do |
I had this thought the other day, and I'll just note it down here lest I forget. It's just an idea. What do you think?
Sanctuary has always conceptually differentiated between Objects and StrMaps, where an Object is like a struct, can have methods, additional properties on its prototype, etc. and a StrMap is a mapping of keys to values of the same type.
For StrMaps, the prototype of an object is ignored, and only values on the surface of the object are acknowledged. For example:
For Objects, properties on the prototype are also acknowledged, for example:
This is often one of the toughest concepts to explain to newcomers, I find.
My proposal is that Sanctuary (or sanctuary-def, really) would no longer determine whether an Object is a StrMap based on the types of its values, but instead, very simply, based on whether the object has a prototype. In other words:
Users can create Objects without prototypes with
Object.assign (Object.create (null), {...props})
. Sanctuary could provide aStrMap
constructor to make this easier:StrMap ({...props})
.I see the following benefits:
The text was updated successfully, but these errors were encountered: