reference-map
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -6,2 +6,3 @@ module.exports = class ReferanceMap { | ||
constructor () { | ||
this.intRefProp = Symbol('int') | ||
this._map = [] | ||
@@ -18,3 +19,8 @@ } | ||
add (obj, type) { | ||
return this._map.push({obj, type}) - 1 | ||
let ref = obj[this.intRefProp] | ||
if (ref === undefined) { | ||
ref = this._map.push({obj, type}) - 1 | ||
obj[this.intRefProp] = ref | ||
} | ||
return ref | ||
} | ||
@@ -21,0 +27,0 @@ |
{ | ||
"name": "reference-map", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "This is a simple determinstic map that maps POJOs to an integer", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,3 +5,3 @@ const tape = require('tape') | ||
tape('referance mapping', t => { | ||
t.plan(11) | ||
t.plan(12) | ||
const referanceMap = new ReferanceMap() | ||
@@ -25,2 +25,6 @@ const obj1 = {} | ||
const dupRef = referanceMap.add(obj2) | ||
t.equals(dupRef, ref2, 'detect duplicate refs') | ||
referanceMap.delete(ref1) | ||
@@ -27,0 +31,0 @@ try { |
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
63777
522