Skip to content
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

Immutable stack #44

Merged
merged 5 commits into from
Jan 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ function createReaderHandlers(extras, recordMap, missingRecordHandler) {
iS: function(v) {
return Immutable.Set(v);
},
iStk: function(v) {
return Immutable.Stack(v);
},
iOS: function(v) {
return Immutable.OrderedSet(v);
},
Expand Down Expand Up @@ -103,6 +106,17 @@ function createWriterHandlers(extras, recordMap, predicate) {
return v.toArray();
}
}),
Immutable.Stack, transit.makeWriteHandler({
tag: function() {
return "iStk";
},
rep: function(v) {
if (predicate) {
v = v.filter(predicate);
}
return v.toArray();
}
}),
Immutable.Set, transit.makeWriteHandler({
tag: function() {
return "iS";
Expand Down
4 changes: 2 additions & 2 deletions test/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ exports.samples = Immutable.Map({

"Immutable": Immutable.Map({

"Stack": new Immutable.Stack([1, 2, 3]),

"Maps": Immutable.Map({"abc": "def\nghi"}),

"Maps with numeric keys": Immutable.Map().set(1, 2),
Expand Down Expand Up @@ -60,9 +62,7 @@ exports.samples = Immutable.Map({
a: Immutable.Map({1: 2}),
b: Immutable.Map({3: 4})
}

})

});

// This is a hack because records and maps are considered equivalent by
Expand Down
10 changes: 10 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,16 @@ describe('transit', function() {
expect(result.size).to.eql(3);
});

it('can ignore Stack entries', function() {
var input = Immutable.Stack.of(1, 2, 3, 'a');
filter = transit.withFilter(function(val) {
return typeof val === 'number';
});
var result = filter.fromJSON(filter.toJSON(input));
expect(result.includes('a')).to.eql(false);
expect(result.size).to.eql(3);
});

it('can ignore OrderedSet entries', function() {
var input = Immutable.Set.of(1, 2, 3, 3, 'a');
filter = transit.withFilter(function(val) {
Expand Down