Git Product home page Git Product logo

Comments (9)

petermichaux avatar petermichaux commented on August 21, 2024

es-discuss mailing list thread

https://mail.mozilla.org/pipermail/es-discuss/2013-March/029525.html

from maria.

petermichaux avatar petermichaux commented on August 21, 2024

And now also the following threads.

from maria.

petermichaux avatar petermichaux commented on August 21, 2024

I'm looking at section 15.16 Set Objects in the March 8, 2013 ECMAScript draft which is available at http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts

I'm also looking at version 3 of https://github.com/petermichaux/hormigas which defines hormigas.ObjectSet: the base class for maria.SetModel.

Set constructor can be called with iterable and comparator optional arguments. Currently the comparator is only allowed to be is. hormigas.ObjectSet constructor will add all its arguments as elements of the set. The comparator is essentially ===.

Set.prototype.size vs hormigas.ObjectSet.prototype.length.

Set.prototype.add returns the set object. hormigas.ObjectSet.prototype.add returns true if the set was modified otherwise false.

Set.prototype.clear removes all elements from the set and returns undefined. hormigas.ObjectSet.prototype.empty does the same but returns true if the set was modified otherwise false.

Set.prototype.delete returns true if the set was modified otherwise false. hormigas.ObjectSet.prototype['delete'] returns true if the set was modified otherwise false.

Set.prototype.forEach calls the callback function with three arguments (element, element, set) according to the second NOTE in section 15.16.4.6 but the specification algorithm in the same section has step 8.a.i calling with only two arguments: (element, set). hormigas.ObjectSet.prototype.forEach calls the callback with the two argument version.

Set does not have a reduce method but iteration order of a Set is specified as insertion order. On the other hand, hormigas.ObjectSet iteration order is not specified so hormigas.ObjectSet.prototype.reduce is a bit of an odd duck. If iteration order was specified then both reduce and reduceRight would be appropriate.

Set does not have isEmpty, toArray, some, or every methods.

Set does not have a map method. hormigas.ObjectSet.prototype.map returns an array. Same for filter. It is likely these should return sets of some sort.

Set.prototype.has and hormigas.ObjectSet.prototype.has look to be the same.

from maria.

petermichaux avatar petermichaux commented on August 21, 2024

The goal of modifying hormigas.ObjectSet would be to align it more closely with the ECMAScript Set. This way, one day, maria.SetModel could inherit directly from Set. Due to the changes in hormigas.ObjectSet to align it more with Set, the results on maria.SetModel would be the following.

Likely important breaking changes to maria.SetModel would be

  • change length to size
  • change empty to clear

Likely less important breaking changes to maria.SetModel would be

  • possibly change forEach and the other iterator methods to send three arguments to the callback function. I don't imagine many folks would be using more than the first argument to the callback function anyway. Need a response to https://mail.mozilla.org/pipermail/es-discuss/2013-April/029600.html in order to decide what to do here.
  • possibly change the return values of map and filter to sets. This is a tricky issue if maria.ObjectSet has been subclassed. Possibly just remove map and filter as this issue may not have a reasonable solution that can be implemented to execute efficiently. checkit.TodosModel uses map and filter but these could be run on the results of toArray instead (e.g. change .filter( to .toArray().filter().

Non-breaking, optional changes to maria.SetModel would be

  • specified iteration order
  • add reduceRight

from maria.

jamesladd avatar jamesladd commented on August 21, 2024

I'm in favour of making SetModel closer to the ECMAScript Set.

from maria.

petermichaux avatar petermichaux commented on August 21, 2024

Be careful that the @borrows documentation in maria.SetModel is updated accordingly to any name changes. [obsolete comment]

from maria.

petermichaux avatar petermichaux commented on August 21, 2024

Be careful to rename maria.SetModel.prototype.empty. [I've searched for every use of the word "empty" in the whole project.]

from maria.

petermichaux avatar petermichaux commented on August 21, 2024

Note that the examples and the quick start tutorial use filter, for example. [fixed]

from maria.

petermichaux avatar petermichaux commented on August 21, 2024

There are still some differences between hormigas.SetModel and the ECMAScript proposed Set.

The Set constructor takes iterable and comparator as its arguments. hormigas.SetModel takes a variable number of arguments to be added to the set.

Set.prototype.add returns the set object. hormigas.ObjectSet.prototype.add returns true if the set was modified otherwise false.

Set.prototype.clear removes all elements from the set and returns undefined. hormigas.ObjectSet.prototype.clear does the same but returns true if the set was modified otherwise false.

hormigas.ObjectSet.prototype.forEach only sends the item in the set as the first argument to the callback function. Set.prototype.forEach is currently specified to send the item as the first argument, the item again as the second argument, and the set itself as the third argument. Craziness.

There is nothing like hormigas.ObjectSet.prototype.toArray in the current Set spec.


All of these issues can be worked around one day when Set is a viable option and we can shim in maria.SetModel to take care fo any mismatches. There will also be new options like proxies to do multiple inheritance so maria.SetModel can inherit from both maria.Model and Set. This will be important for plugins flexibility.

from maria.

Related Issues (20)

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.