Skip to content

Commit

Permalink
add transducer protocol to List/Map/Set as per cognitect-labs/transdu…
Browse files Browse the repository at this point in the history
  • Loading branch information
don.abrams committed Jul 16, 2015
1 parent c7c4ddc commit a616eca
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 37 deletions.
27 changes: 27 additions & 0 deletions dist/immutable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1958,6 +1958,15 @@
MapPrototype[IS_MAP_SENTINEL] = true;
MapPrototype[DELETE] = MapPrototype.remove;
MapPrototype.removeIn = MapPrototype.deleteIn;
MapPrototype['@@transducer/init'] = function() {
return this.asMutable();
};
MapPrototype['@@transducer/step'] = function(result, arr) {
return result.set(arr[0], arr[1]);
};
MapPrototype['@@transducer/result'] = function(obj) {
return obj.asImmutable();
};


// #pragma Trie Nodes
Expand Down Expand Up @@ -2785,6 +2794,15 @@
ListPrototype.asMutable = MapPrototype.asMutable;
ListPrototype.asImmutable = MapPrototype.asImmutable;
ListPrototype.wasAltered = MapPrototype.wasAltered;
ListPrototype['@@transducer/init'] = function() {
return this.asMutable();
};
ListPrototype['@@transducer/step'] = function(result, arr) {
return result.push(arr);
};
List.prototype['@@transducer/result'] = function(obj) {
return obj.asImmutable();
};



Expand Down Expand Up @@ -3692,6 +3710,15 @@
SetPrototype.withMutations = MapPrototype.withMutations;
SetPrototype.asMutable = MapPrototype.asMutable;
SetPrototype.asImmutable = MapPrototype.asImmutable;
SetPrototype['@@transducer/init'] = function() {
return this.asMutable();
};
SetPrototype['@@transducer/step'] = function(result, arr) {
return result.add(arr);
};
SetPrototype['@@transducer/result'] = function(obj) {
return obj.asImmutable();
};

SetPrototype.__empty = emptySet;
SetPrototype.__make = makeSet;
Expand Down

0 comments on commit a616eca

Please sign in to comment.