transit-immutable-js
Advanced tools
Comparing version 0.7.0 to 0.8.0
37
index.js
@@ -44,2 +44,5 @@ var transit = require('transit-js'); | ||
}, | ||
iStk: function(v) { | ||
return Immutable.Stack(v); | ||
}, | ||
iOS: function(v) { | ||
@@ -84,11 +87,11 @@ return Immutable.OrderedSet(v); | ||
var handlers = transit.map([ | ||
Immutable.Map, transit.makeWriteHandler({ | ||
Immutable.OrderedMap, transit.makeWriteHandler({ | ||
tag: function() { | ||
return 'iM'; | ||
return 'iOM'; | ||
}, | ||
rep: mapSerializer | ||
}), | ||
Immutable.OrderedMap, transit.makeWriteHandler({ | ||
Immutable.Map, transit.makeWriteHandler({ | ||
tag: function() { | ||
return 'iOM'; | ||
return 'iM'; | ||
}, | ||
@@ -108,5 +111,5 @@ rep: mapSerializer | ||
}), | ||
Immutable.Set, transit.makeWriteHandler({ | ||
Immutable.Stack, transit.makeWriteHandler({ | ||
tag: function() { | ||
return "iS"; | ||
return "iStk"; | ||
}, | ||
@@ -131,2 +134,13 @@ rep: function(v) { | ||
}), | ||
Immutable.Set, transit.makeWriteHandler({ | ||
tag: function() { | ||
return "iS"; | ||
}, | ||
rep: function(v) { | ||
if (predicate) { | ||
v = v.filter(predicate); | ||
} | ||
return v.toArray(); | ||
} | ||
}), | ||
Function, transit.makeWriteHandler({ | ||
@@ -145,7 +159,7 @@ tag: function() { | ||
rep: function(m) { | ||
if (!('toMap' in m)) { | ||
var e = "Error serializing unrecognized object " + m.toString(); | ||
throw new Error(e); | ||
if ((Immutable.isImmutable && Immutable.isImmutable(m)) || ('toMap' in m)) { | ||
return mapSerializer(Immutable.Map(m)); | ||
} | ||
return mapSerializer(m.toMap()); | ||
var e = "Error serializing unrecognized object " + m.toString(); | ||
throw new Error(e); | ||
} | ||
@@ -199,2 +213,3 @@ }) | ||
/* eslint no-underscore-dangle: 0 */ | ||
/* istanbul ignore next */ | ||
return record._name || record.constructor.name || 'Record'; | ||
@@ -221,3 +236,3 @@ } | ||
recordClasses.forEach(function(RecordType) { | ||
var rec = new RecordType({}); | ||
var rec = new RecordType(); | ||
var recName = recordName(rec); | ||
@@ -224,0 +239,0 @@ |
{ | ||
"name": "transit-immutable-js", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"description": "Transit serialisation for Immutable.js", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha", | ||
"test:3": "npm install --no-save immutable@^3.7.4 && mocha", | ||
"test:4": "npm install --no-save immutable@^4.0.0-rc.12 && mocha", | ||
"test": "npm run test:3 && npm run test:4", | ||
"lint": "eslint .", | ||
"coverage": "istanbul cover _mocha --" | ||
"coverage": "nyc npm test && nyc report --reporter=lcov --reporter=json" | ||
}, | ||
@@ -30,7 +32,7 @@ "repository": { | ||
"eslint": "^0.24.1", | ||
"immutable": "^3.7.4", | ||
"istanbul": "^0.3.14", | ||
"immutable": ">=3.7.4", | ||
"mocha": "^2.2.5", | ||
"nyc": "^14.1.1", | ||
"transit-js": "^0.8.807" | ||
} | ||
} |
@@ -12,2 +12,4 @@ var chai = require('chai'); | ||
"Stack": new Immutable.Stack([1, 2, 3]), | ||
"Maps": Immutable.Map({"abc": "def\nghi"}), | ||
@@ -64,5 +66,3 @@ | ||
} | ||
}) | ||
}); | ||
@@ -69,0 +69,0 @@ |
@@ -238,2 +238,12 @@ /* eslint-env mocha */ | ||
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() { | ||
@@ -240,0 +250,0 @@ var input = Immutable.Set.of(1, 2, 3, 3, 'a'); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36685
799
12