immutable-class
Advanced tools
Comparing version 0.6.40 to 0.6.41
@@ -65,2 +65,3 @@ export interface Validator { | ||
equals(other: BaseImmutable<ValueType, JSType>): boolean; | ||
equivalent(other: BaseImmutable<ValueType, JSType>): boolean; | ||
get(propName: string): any; | ||
@@ -67,0 +68,0 @@ change(propName: string, newValue: any): this; |
@@ -191,4 +191,3 @@ "use strict"; | ||
var equal = property.equal || equality_1.generalEqual; | ||
var getter = 'get' + firstUp(propertyName); | ||
if (!equal(this[getter](), other[getter]())) | ||
if (!equal(this[propertyName], other[propertyName])) | ||
return false; | ||
@@ -198,2 +197,19 @@ } | ||
}; | ||
BaseImmutable.prototype.equivalent = function (other) { | ||
if (!other) | ||
return false; | ||
if (this === other) | ||
return true; | ||
if (!(other instanceof this.constructor)) | ||
return false; | ||
var properties = this.ownProperties(); | ||
for (var _i = 0, properties_6 = properties; _i < properties_6.length; _i++) { | ||
var property = properties_6[_i]; | ||
var propertyName = property.name; | ||
var equal = property.equal || equality_1.generalEqual; | ||
if (!equal(this.get(propertyName), other.get(propertyName))) | ||
return false; | ||
} | ||
return true; | ||
}; | ||
BaseImmutable.prototype.get = function (propName) { | ||
@@ -200,0 +216,0 @@ var getter = this['get' + firstUp(propName)]; |
@@ -55,8 +55,15 @@ "use strict"; | ||
describe('equals', function () { | ||
it('works with default values', function () { | ||
it('is not equal if new value is explicitly set', function () { | ||
var car0 = car_mock_1.Car.fromJS({ name: 'pouet' }); | ||
var car1 = car0.change('driver', car0.get('driver')); | ||
chai_1.expect(car0.equals(car1)).to.be.true; | ||
chai_1.expect(car0.equals(car1)).to.be.false; | ||
}); | ||
}); | ||
describe('equivalent', function () { | ||
it('is equivalent if new value is explicitly set', function () { | ||
var car0 = car_mock_1.Car.fromJS({ name: 'pouet' }); | ||
var car1 = car0.change('driver', car0.get('driver')); | ||
chai_1.expect(car0.equivalent(car1)).to.be.true; | ||
}); | ||
}); | ||
describe('deepChange', function () { | ||
@@ -63,0 +70,0 @@ it('works', function () { |
{ | ||
"name": "immutable-class", | ||
"version": "0.6.40", | ||
"version": "0.6.41", | ||
"description": "A template for creating immutable classes", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
87803
1815