From 8b163e4182c36c858d3ee1f7ceac7ef24e88a91c Mon Sep 17 00:00:00 2001 From: Justin Date: Mon, 6 Jun 2016 17:54:07 +0000 Subject: [PATCH] fix copy bug --- src/Address.js | 20 +++++++++++++++++++- src/Agent.js | 20 +++++++++++++++++++- src/Attribution.js | 20 +++++++++++++++++++- src/Conclusion.js | 20 +++++++++++++++++++- src/Coverage.js | 20 +++++++++++++++++++- src/Date.js | 20 +++++++++++++++++++- src/Document.js | 20 +++++++++++++++++++- src/Event.js | 20 +++++++++++++++++++- src/EventRole.js | 20 +++++++++++++++++++- src/EvidenceReference.js | 20 +++++++++++++++++++- src/ExtensibleData.js | 19 +++++++++++++++++++ src/Fact.js | 20 +++++++++++++++++++- src/GedcomX.js | 26 +++++++++++++++++++++++++- src/Gender.js | 20 +++++++++++++++++++- src/Identifiers.js | 20 ++++++++++++++++++++ src/Name.js | 20 +++++++++++++++++++- src/NameForm.js | 20 +++++++++++++++++++- src/NamePart.js | 20 +++++++++++++++++++- src/Note.js | 20 +++++++++++++++++++- src/OnlineAccount.js | 20 +++++++++++++++++++- src/Person.js | 20 +++++++++++++++++++- src/PlaceDescription.js | 20 +++++++++++++++++++- src/PlaceReference.js | 20 +++++++++++++++++++- src/Qualifier.js | 19 +++++++++++++++++++ src/Relationship.js | 20 +++++++++++++++++++- src/ResourceReference.js | 19 +++++++++++++++++++ src/SourceCitation.js | 20 +++++++++++++++++++- src/SourceDescription.js | 20 +++++++++++++++++++- src/SourceReference.js | 20 +++++++++++++++++++- src/Subject.js | 20 +++++++++++++++++++- src/TextValue.js | 19 +++++++++++++++++++ src/utils.js | 23 +++++++++++++++++++++++ test/Address.js | 6 ++++++ test/Agent.js | 6 ++++++ test/Attribution.js | 6 ++++++ test/Conclusion.js | 6 ++++++ test/Coverage.js | 6 ++++++ test/Date.js | 6 ++++++ test/Document.js | 6 ++++++ test/Event.js | 6 ++++++ test/EventRole.js | 6 ++++++ test/EvidenceReference.js | 6 ++++++ test/ExtensibleData.js | 6 ++++++ test/Fact.js | 6 ++++++ test/GedcomX.js | 13 ++++--------- test/Gender.js | 6 ++++++ test/Name.js | 6 ++++++ test/NameForm.js | 6 ++++++ test/NamePart.js | 6 ++++++ test/Note.js | 6 ++++++ test/OnlineAccount.js | 6 ++++++ test/Person.js | 6 ++++++ test/PlaceDescription.js | 6 ++++++ test/PlaceReference.js | 6 ++++++ test/Qualifier.js | 6 ++++++ test/Relationship.js | 6 ++++++ test/ResourceReference.js | 6 ++++++ test/SourceCitation.js | 6 ++++++ test/SourceDescription.js | 6 ++++++ test/SourceReference.js | 6 ++++++ test/Subject.js | 6 ++++++ test/TextValue.js | 6 ++++++ 62 files changed, 797 insertions(+), 35 deletions(-) create mode 100644 src/utils.js diff --git a/src/Address.js b/src/Address.js index 1fd6e2e..f2f3203 100644 --- a/src/Address.js +++ b/src/Address.js @@ -1,4 +1,5 @@ -var ExtensibleData = require('./ExtensibleData'); +var ExtensibleData = require('./ExtensibleData'), + utils = require('./utils'); /** * An address. @@ -13,6 +14,11 @@ var Address = function(json){ return new Address(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(Address.isInstance(json)){ + return json; + } + ExtensibleData.call(this, json); if(json){ @@ -32,6 +38,18 @@ var Address = function(json){ Address.prototype = Object.create(ExtensibleData.prototype); +Address._gedxClass = Address.prototype._gedxClass = 'GedcomX.Address'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +Address.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Get the complete address value * diff --git a/src/Agent.js b/src/Agent.js index c14fee4..3c65909 100644 --- a/src/Agent.js +++ b/src/Agent.js @@ -3,7 +3,8 @@ var ExtensibleData = require('./ExtensibleData'), OnlineAccount = require('./OnlineAccount'), Address = require('./Address'), Identifiers = require('./Identifiers'), - TextValue = require('./TextValue'); + TextValue = require('./TextValue'), + utils = require('./utils'); /** * Someone or something that curates genealogical data, such as a genealogical @@ -19,6 +20,11 @@ var Agent = function(json){ return new Agent(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(Agent.isInstance(json)){ + return json; + } + ExtensibleData.call(this, json); if(json){ @@ -36,6 +42,18 @@ var Agent = function(json){ Agent.prototype = Object.create(ExtensibleData.prototype); +Agent._gedxClass = Agent.prototype._gedxClass = 'GedcomX.Agent'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +Agent.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Get the identifiers * diff --git a/src/Attribution.js b/src/Attribution.js index a14a385..e0f1305 100644 --- a/src/Attribution.js +++ b/src/Attribution.js @@ -1,5 +1,6 @@ var ExtensibleData = require('./ExtensibleData'), - ResourceReference = require('./ResourceReference'); + ResourceReference = require('./ResourceReference'), + utils = require('./utils'); /** * Define who is contributing information, when they contributed it, @@ -15,6 +16,11 @@ var Attribution = function(json){ return new Attribution(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(Attribution.isInstance(json)){ + return json; + } + ExtensibleData.call(this, json); if(json){ @@ -28,6 +34,18 @@ var Attribution = function(json){ Attribution.prototype = Object.create(ExtensibleData.prototype); +Attribution._gedxClass = Attribution.prototype._gedxClass = 'GedcomX.Attribution'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +Attribution.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Get the change message. * diff --git a/src/Conclusion.js b/src/Conclusion.js index 81bd8b2..17ac8a3 100644 --- a/src/Conclusion.js +++ b/src/Conclusion.js @@ -2,7 +2,8 @@ var ExtensibleData = require('./ExtensibleData'), Attribution = require('./Attribution'), ResourceReference = require('./ResourceReference'), Note = require('./Note'), - SourceReference = require('./SourceReference'); + SourceReference = require('./SourceReference'), + utils = require('./utils'); /** * An abstract concept for a basic genealogical data item. @@ -17,6 +18,11 @@ var Conclusion = function(json){ return new Conclusion(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(Conclusion.isInstance(json)){ + return json; + } + ExtensibleData.call(this, json); if(json){ @@ -31,6 +37,18 @@ var Conclusion = function(json){ Conclusion.prototype = Object.create(ExtensibleData.prototype); +Conclusion._gedxClass = Conclusion.prototype._gedxClass = 'GedcomX.Conclusion'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +Conclusion.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Get the attribution. * diff --git a/src/Coverage.js b/src/Coverage.js index 45bfa60..8f0e4d3 100644 --- a/src/Coverage.js +++ b/src/Coverage.js @@ -1,6 +1,7 @@ var ExtensibleData = require('./ExtensibleData'), GDate = require('./Date'), - PlaceReference = require('./PlaceReference'); + PlaceReference = require('./PlaceReference'), + utils = require('./utils'); /** * A description of the spatial and temporal coverage of a resource. @@ -15,6 +16,11 @@ var Coverage = function(json){ return new Coverage(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(Coverage.isInstance(json)){ + return json; + } + ExtensibleData.call(this, json); if(json){ @@ -25,6 +31,18 @@ var Coverage = function(json){ Coverage.prototype = Object.create(ExtensibleData.prototype); +Coverage._gedxClass = Coverage.prototype._gedxClass = 'GedcomX.Coverage'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +Coverage.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Get the spatial coverage * diff --git a/src/Date.js b/src/Date.js index db6045f..d745fdb 100644 --- a/src/Date.js +++ b/src/Date.js @@ -1,4 +1,5 @@ -var ExtensibleData = require('./ExtensibleData'); +var ExtensibleData = require('./ExtensibleData'), + utils = require('./utils'); /** * A date. @@ -14,6 +15,11 @@ var GDate = function(json){ return new GDate(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(GDate.isInstance(json)){ + return json; + } + ExtensibleData.call(this, json); if(json){ @@ -24,6 +30,18 @@ var GDate = function(json){ GDate.prototype = Object.create(ExtensibleData.prototype); +GDate._gedxClass = GDate.prototype._gedxClass = 'GedcomX.Date'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +GDate.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Get the original date value * diff --git a/src/Document.js b/src/Document.js index eb0c27c..eca8533 100644 --- a/src/Document.js +++ b/src/Document.js @@ -1,5 +1,6 @@ var Conclusion = require('./Conclusion'), - Attribution = require('./Attribution'); + Attribution = require('./Attribution'), + utils = require('./utils'); /** * A textual document @@ -14,6 +15,11 @@ var Document = function(json){ return new Document(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(Document.isInstance(json)){ + return json; + } + Conclusion.call(this, json); if(json){ @@ -27,6 +33,18 @@ var Document = function(json){ Document.prototype = Object.create(Conclusion.prototype); +Document._gedxClass = Document.prototype._gedxClass = 'GedcomX.Document'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +Document.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Get the type * diff --git a/src/Event.js b/src/Event.js index c2a736b..51981d8 100644 --- a/src/Event.js +++ b/src/Event.js @@ -1,7 +1,8 @@ var Subject = require('./Subject'), GDate = require('./Date'), PlaceReference = require('./PlaceReference'), - EventRole = require('./EventRole'); + EventRole = require('./EventRole'), + utils = require('./utils'); /** * An event. @@ -16,6 +17,11 @@ var Event = function(json){ return new Event(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(Event.isInstance(json)){ + return json; + } + Subject.call(this, json); if(json){ @@ -28,6 +34,18 @@ var Event = function(json){ Event.prototype = Object.create(Subject.prototype); +Event._gedxClass = Event.prototype._gedxClass = 'GedcomX.Event'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +Event.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Get the type * diff --git a/src/EventRole.js b/src/EventRole.js index 0eddcbb..a2afeef 100644 --- a/src/EventRole.js +++ b/src/EventRole.js @@ -1,5 +1,6 @@ var Conclusion = require('./Conclusion'), - ResourceReference = require('./ResourceReference'); + ResourceReference = require('./ResourceReference'), + utils = require('./utils'); /** * A role that a specific person plays in an event. @@ -14,6 +15,11 @@ var EventRole = function(json){ return new EventRole(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(Conclusion.isInstance(json)){ + return json; + } + Conclusion.call(this, json); if(json){ @@ -25,6 +31,18 @@ var EventRole = function(json){ EventRole.prototype = Object.create(Conclusion.prototype); +Conclusion._gedxClass = Conclusion.prototype._gedxClass = 'GedcomX.Conclusion'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +Conclusion.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Get the person * diff --git a/src/EvidenceReference.js b/src/EvidenceReference.js index 770ab36..18f90fb 100644 --- a/src/EvidenceReference.js +++ b/src/EvidenceReference.js @@ -1,5 +1,6 @@ var ResourceReference = require('./ResourceReference'), - Attribution = require('./Attribution'); + Attribution = require('./Attribution'), + utils = require('./utils'); /** * A generic reference to a resource. @@ -14,6 +15,11 @@ var EvidenceReference = function(json){ return new EvidenceReference(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(ResourceReference.isInstance(json)){ + return json; + } + ResourceReference.call(this, json); if(json){ @@ -23,6 +29,18 @@ var EvidenceReference = function(json){ EvidenceReference.prototype = Object.create(ResourceReference.prototype); +ResourceReference._gedxClass = ResourceReference.prototype._gedxClass = 'GedcomX.ResourceReference'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +ResourceReference.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Get the attribution. * diff --git a/src/ExtensibleData.js b/src/ExtensibleData.js index c76c692..724e92e 100644 --- a/src/ExtensibleData.js +++ b/src/ExtensibleData.js @@ -1,3 +1,5 @@ +var utils = require('./utils'); + /** * A set of data that supports extension elements. * @@ -11,11 +13,28 @@ var ExtensibleData = function(json){ return new ExtensibleData(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(ExtensibleData.isInstance(json)){ + return json; + } + if(json){ this.setId(json.id); } }; +ExtensibleData._gedxClass = ExtensibleData.prototype._gedxClass = 'GedcomX.ExtensibleData'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +ExtensibleData.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Get the object's id. * diff --git a/src/Fact.js b/src/Fact.js index d1b2da8..abc385e 100644 --- a/src/Fact.js +++ b/src/Fact.js @@ -1,7 +1,8 @@ var Conclusion = require('./Conclusion'), PlaceReference = require('./PlaceReference'), GDate = require('./Date'), - Qualifier = require('./Qualifier'); + Qualifier = require('./Qualifier'), + utils = require('./utils'); /** * A fact for a person or relationship. @@ -16,6 +17,11 @@ var Fact = function(json){ return new Fact(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(Fact.isInstance(json)){ + return json; + } + Conclusion.call(this, json); if(json){ @@ -29,6 +35,18 @@ var Fact = function(json){ Fact.prototype = Object.create(Conclusion.prototype); +Fact._gedxClass = Fact.prototype._gedxClass = 'GedcomX.Fact'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +Fact.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Get the fact type * diff --git a/src/GedcomX.js b/src/GedcomX.js index fc2f190..0018dde 100644 --- a/src/GedcomX.js +++ b/src/GedcomX.js @@ -6,7 +6,8 @@ var ExtensibleData = require('./ExtensibleData'), Event = require('./Event'), Document = require('./Document'), PlaceDescription = require('./PlaceDescription'), - Attribution = require('./Attribution'); + Attribution = require('./Attribution'), + utils = require('./utils'); /** * A GEDCOM X document. @@ -21,6 +22,17 @@ var GedcomX = function(json){ return new GedcomX(json); } + // If the given object is already an instance then just return it. DON'T copy it. + /* + if(utils.instanceOf(json, this._gedxClass)){ + return json; + } + */ + + if(GedcomX.isInstance(json)){ + return json; + } + ExtensibleData.call(this, json); if(json){ @@ -37,6 +49,18 @@ var GedcomX = function(json){ GedcomX.prototype = Object.create(ExtensibleData.prototype); +GedcomX._gedxClass = GedcomX.prototype._gedxClass = 'GedcomX'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +GedcomX.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Get the persons * diff --git a/src/Gender.js b/src/Gender.js index 2fc1377..65b36a3 100644 --- a/src/Gender.js +++ b/src/Gender.js @@ -1,4 +1,5 @@ -var Conclusion = require('./Conclusion'); +var Conclusion = require('./Conclusion'), + utils = require('./utils'); /** * A gender conclusion. @@ -13,6 +14,11 @@ var Gender = function(json){ return new Gender(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(Gender.isInstance(json)){ + return json; + } + Conclusion.call(this, json); if(json){ @@ -22,6 +28,18 @@ var Gender = function(json){ Gender.prototype = Object.create(Conclusion.prototype); +Gender._gedxClass = Gender.prototype._gedxClass = 'GedcomX.Gender'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +Gender.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Get the gender type * diff --git a/src/Identifiers.js b/src/Identifiers.js index e3c4754..6154813 100644 --- a/src/Identifiers.js +++ b/src/Identifiers.js @@ -1,3 +1,5 @@ +var utils = require('./utils'); + /** * Manage the set of identifers for an object. * @@ -11,6 +13,11 @@ var Identifiers = function(json){ return new Identifiers(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(Identifiers.isInstance(json)){ + return json; + } + this.identifiers = {}; if(json){ @@ -22,6 +29,19 @@ var Identifiers = function(json){ } }; +Identifiers._gedxClass = Identifiers.prototype._gedxClass = 'GedcomX.Identifiers'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +Identifiers.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + + /** * Export the object as JSON * diff --git a/src/Name.js b/src/Name.js index 3bbc942..da43eee 100644 --- a/src/Name.js +++ b/src/Name.js @@ -1,6 +1,7 @@ var Conclusion = require('./Conclusion'), NameForm = require('./NameForm'), - GDate = require('./Date'); + GDate = require('./Date'), + utils = require('./utils'); /** * A name. @@ -15,6 +16,11 @@ var Name = function(json){ return new Name(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(Name.isInstance(json)){ + return json; + } + Conclusion.call(this, json); if(json){ @@ -26,6 +32,18 @@ var Name = function(json){ Name.prototype = Object.create(Conclusion.prototype); +Name._gedxClass = Name.prototype._gedxClass = 'GedcomX.Name'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +Name.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Get the name type * diff --git a/src/NameForm.js b/src/NameForm.js index ec254b7..88dc89a 100644 --- a/src/NameForm.js +++ b/src/NameForm.js @@ -1,5 +1,6 @@ var ExtensibleData = require('./ExtensibleData'), - NamePart = require('./NamePart'); + NamePart = require('./NamePart'), + utils = require('./utils'); /** * A form of a name. @@ -14,6 +15,11 @@ var NameForm = function(json){ return new NameForm(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(NameForm.isInstance(json)){ + return json; + } + ExtensibleData.call(this, json); if(json){ @@ -25,6 +31,18 @@ var NameForm = function(json){ NameForm.prototype = Object.create(ExtensibleData.prototype); +NameForm._gedxClass = NameForm.prototype._gedxClass = 'GedcomX.NameForm'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +NameForm.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Get the lang tag * diff --git a/src/NamePart.js b/src/NamePart.js index 975b137..48b3ea9 100644 --- a/src/NamePart.js +++ b/src/NamePart.js @@ -1,5 +1,6 @@ var ExtensibleData = require('./ExtensibleData'), - Qualifier = require('./Qualifier'); + Qualifier = require('./Qualifier'), + utils = require('./utils'); /** * A part of a name. @@ -14,6 +15,11 @@ var NamePart = function(json){ return new NamePart(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(NamePart.isInstance(json)){ + return json; + } + ExtensibleData.call(this, json); if(json){ @@ -25,6 +31,18 @@ var NamePart = function(json){ NamePart.prototype = Object.create(ExtensibleData.prototype); +NamePart._gedxClass = NamePart.prototype._gedxClass = 'GedcomX.NamePart'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +NamePart.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Get the type * diff --git a/src/Note.js b/src/Note.js index fd8365d..7517a48 100644 --- a/src/Note.js +++ b/src/Note.js @@ -1,5 +1,6 @@ var ExtensibleData = require('./ExtensibleData'), - Attribution = require('./Attribution'); + Attribution = require('./Attribution'), + utils = require('./utils'); /** * A note about a resource. @@ -14,6 +15,11 @@ var Note = function(json){ return new Note(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(Note.isInstance(json)){ + return json; + } + ExtensibleData.call(this, json); if(json){ @@ -26,6 +32,18 @@ var Note = function(json){ Note.prototype = Object.create(ExtensibleData.prototype); +Note._gedxClass = Note.prototype._gedxClass = 'GedcomX.Note'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +Note.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Get the language identifier. * diff --git a/src/OnlineAccount.js b/src/OnlineAccount.js index 8a18308..e4ce3a7 100644 --- a/src/OnlineAccount.js +++ b/src/OnlineAccount.js @@ -1,5 +1,6 @@ var ExtensibleData = require('./ExtensibleData'), - ResourceReference = require('./ResourceReference'); + ResourceReference = require('./ResourceReference'), + utils = require('./utils'); /** * An online account for a web application. @@ -14,6 +15,11 @@ var OnlineAccount = function(json){ return new OnlineAccount(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(OnlineAccount.isInstance(json)){ + return json; + } + ExtensibleData.call(this, json); if(json){ @@ -24,6 +30,18 @@ var OnlineAccount = function(json){ OnlineAccount.prototype = Object.create(ExtensibleData.prototype); +OnlineAccount._gedxClass = OnlineAccount.prototype._gedxClass = 'GedcomX.OnlineAccount'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +OnlineAccount.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Get the service home page * diff --git a/src/Person.js b/src/Person.js index 462756c..e769e62 100644 --- a/src/Person.js +++ b/src/Person.js @@ -1,7 +1,8 @@ var Subject = require('./Subject'), Gender = require('./Gender'), Name = require('./Name'), - Fact = require('./Fact'); + Fact = require('./Fact'), + utils = require('./utils'); /** * A person. @@ -16,6 +17,11 @@ var Person = function(json){ return new Person(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(Person.isInstance(json)){ + return json; + } + Subject.call(this, json); if(json){ @@ -28,6 +34,18 @@ var Person = function(json){ Person.prototype = Object.create(Subject.prototype); +Person._gedxClass = Person.prototype._gedxClass = 'GedcomX.Person'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +Person.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Check whether the person is marked as private * diff --git a/src/PlaceDescription.js b/src/PlaceDescription.js index af4300b..654a312 100644 --- a/src/PlaceDescription.js +++ b/src/PlaceDescription.js @@ -1,7 +1,8 @@ var Subject = require('./Subject'), ResourceReference = require('./ResourceReference'), TextValue = require('./TextValue'), - GDate = require('./Date'); + GDate = require('./Date'), + utils = require('./utils'); /** * A description of a place @@ -16,6 +17,11 @@ var PlaceDescription = function(json){ return new PlaceDescription(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(PlaceDescription.isInstance(json)){ + return json; + } + Subject.call(this, json); if(json){ @@ -32,6 +38,18 @@ var PlaceDescription = function(json){ PlaceDescription.prototype = Object.create(Subject.prototype); +PlaceDescription._gedxClass = PlaceDescription.prototype._gedxClass = 'GedcomX.PlaceDescription'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +PlaceDescription.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Get the type * diff --git a/src/PlaceReference.js b/src/PlaceReference.js index f212f83..8a5917b 100644 --- a/src/PlaceReference.js +++ b/src/PlaceReference.js @@ -1,4 +1,5 @@ -var ExtensibleData = require('./ExtensibleData'); +var ExtensibleData = require('./ExtensibleData'), + utils = require('./utils'); /** * A reference to a {@link PlaceDescription}. @@ -13,6 +14,11 @@ var PlaceReference = function(json){ return new PlaceReference(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(ExtensibleData.isInstance(json)){ + return json; + } + ExtensibleData.call(this, json); if(json){ @@ -23,6 +29,18 @@ var PlaceReference = function(json){ PlaceReference.prototype = Object.create(ExtensibleData.prototype); +ExtensibleData._gedxClass = ExtensibleData.prototype._gedxClass = 'GedcomX.ExtensibleData'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +ExtensibleData.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Get the original text * diff --git a/src/Qualifier.js b/src/Qualifier.js index 4ee505b..5e603c9 100644 --- a/src/Qualifier.js +++ b/src/Qualifier.js @@ -1,3 +1,5 @@ +var utils = require('./utils'); + /** * Qualifiers are used to supply additional details about a piece of data. * @@ -11,12 +13,29 @@ var Qualifier = function(json){ return new Qualifier(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(Qualifier.isInstance(json)){ + return json; + } + if(json){ this.setName(json.name); this.setValue(json.value); } }; +Qualifier._gedxClass = Qualifier.prototype._gedxClass = 'GedcomX.Qualifier'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +Qualifier.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Get the name * diff --git a/src/Relationship.js b/src/Relationship.js index 5947d62..eb7514e 100644 --- a/src/Relationship.js +++ b/src/Relationship.js @@ -1,6 +1,7 @@ var Subject = require('./Subject'), Fact = require('./Fact'), - ResourceReference = require('./ResourceReference'); + ResourceReference = require('./ResourceReference'), + utils = require('./utils'); /** * A relationship. @@ -15,6 +16,11 @@ var Relationship = function(json){ return new Relationship(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(Relationship.isInstance(json)){ + return json; + } + Subject.call(this, json); if(json){ @@ -27,6 +33,18 @@ var Relationship = function(json){ Relationship.prototype = Object.create(Subject.prototype); +Relationship._gedxClass = Relationship.prototype._gedxClass = 'GedcomX.Relationship'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +Relationship.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Get the relationship type * diff --git a/src/ResourceReference.js b/src/ResourceReference.js index 6dac9d0..358b6f8 100644 --- a/src/ResourceReference.js +++ b/src/ResourceReference.js @@ -1,3 +1,5 @@ +var utils = require('./utils'); + /** * A generic reference to a resource. * @@ -11,11 +13,28 @@ var ResourceReference = function(json){ return new ResourceReference(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(ResourceReference.isInstance(json)){ + return json; + } + if(json){ this.setResource(json.resource); } }; +ResourceReference._gedxClass = ResourceReference.prototype._gedxClass = 'GedcomX.ResourceReference'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +ResourceReference.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Get the resource URI * diff --git a/src/SourceCitation.js b/src/SourceCitation.js index e332d90..ed221d0 100644 --- a/src/SourceCitation.js +++ b/src/SourceCitation.js @@ -1,4 +1,5 @@ -var ExtensibleData = require('./ExtensibleData'); +var ExtensibleData = require('./ExtensibleData'), + utils = require('./utils'); /** * A source citation. @@ -13,6 +14,11 @@ var SourceCitation = function(json){ return new SourceCitation(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(SourceCitation.isInstance(json)){ + return json; + } + ExtensibleData.call(this, json); if(json){ @@ -23,6 +29,18 @@ var SourceCitation = function(json){ SourceCitation.prototype = Object.create(ExtensibleData.prototype); +SourceCitation._gedxClass = SourceCitation.prototype._gedxClass = 'GedcomX.SourceCitation'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +SourceCitation.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Get the lang * diff --git a/src/SourceDescription.js b/src/SourceDescription.js index 36cd108..8079a12 100644 --- a/src/SourceDescription.js +++ b/src/SourceDescription.js @@ -6,7 +6,8 @@ var ExtensibleData = require('./ExtensibleData'), Note = require('./Note'), Attribution = require('./Attribution'), Coverage = require('./Coverage'), - Identifiers = require('./Identifiers'); + Identifiers = require('./Identifiers'), + utils = require('./utils'); /** * A description of a source. @@ -21,6 +22,11 @@ var SourceDescription = function(json){ return new SourceDescription(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(SourceDescription.isInstance(json)){ + return json; + } + ExtensibleData.call(this, json); if(json){ @@ -47,6 +53,18 @@ var SourceDescription = function(json){ SourceDescription.prototype = Object.create(ExtensibleData.prototype); +SourceDescription._gedxClass = SourceDescription.prototype._gedxClass = 'GedcomX.SourceDescription'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +SourceDescription.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Get the resource type * diff --git a/src/SourceReference.js b/src/SourceReference.js index b11aa92..6905620 100644 --- a/src/SourceReference.js +++ b/src/SourceReference.js @@ -1,5 +1,6 @@ var ExtensibleData = require('./ExtensibleData'), - Attribution = require('./Attribution'); + Attribution = require('./Attribution'), + utils = require('./utils'); /** * A reference to a discription of a source. @@ -14,6 +15,11 @@ var SourceReference = function(json){ return new SourceReference(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(SourceReference.isInstance(json)){ + return json; + } + ExtensibleData.call(this, json); if(json){ @@ -24,6 +30,18 @@ var SourceReference = function(json){ SourceReference.prototype = Object.create(ExtensibleData.prototype); +SourceReference._gedxClass = SourceReference.prototype._gedxClass = 'GedcomX.SourceReference'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +SourceReference.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Get the description. * diff --git a/src/Subject.js b/src/Subject.js index c1074df..94c92b8 100644 --- a/src/Subject.js +++ b/src/Subject.js @@ -1,7 +1,8 @@ var Conclusion = require('./Conclusion'), Identifiers = require('./Identifiers'), EvidenceReference = require('./EvidenceReference'), - SourceReference = require('./SourceReference'); + SourceReference = require('./SourceReference'), + utils = require('./utils'); /** * An object identified in time and space by various conclusions. @@ -16,6 +17,11 @@ var Subject = function(json){ return new Subject(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(Subject.isInstance(json)){ + return json; + } + Conclusion.call(this, json); if(json){ @@ -28,6 +34,18 @@ var Subject = function(json){ Subject.prototype = Object.create(Conclusion.prototype); +Subject._gedxClass = Subject.prototype._gedxClass = 'GedcomX.Subject'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +Subject.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Is this an extracted conclusion? * diff --git a/src/TextValue.js b/src/TextValue.js index 650087e..902061b 100644 --- a/src/TextValue.js +++ b/src/TextValue.js @@ -1,3 +1,5 @@ +var utils = require('./utils'); + /** * A text value in a specific language. * @@ -11,12 +13,29 @@ var TextValue = function(json){ return new TextValue(json); } + // If the given object is already an instance then just return it. DON'T copy it. + if(TextValue.isInstance(json)){ + return json; + } + if(json){ this.setLang(json.lang); this.setValue(json.value); } }; +TextValue._gedxClass = TextValue.prototype._gedxClass = 'GedcomX.TextValue'; + +/** + * Check whether the given object is an instance of this class. + * + * @param {Object} obj + * @returns {Boolean} + */ +TextValue.isInstance = function(obj){ + return utils.isInstance(obj, this._gedxClass); +}; + /** * Get the lang * diff --git a/src/utils.js b/src/utils.js new file mode 100644 index 0000000..4a79ef6 --- /dev/null +++ b/src/utils.js @@ -0,0 +1,23 @@ +module.exports = { + + /** + * Check whether the given object is an instance of the specified class. + * The necessity for this is discussed in PR #13: https://github.com/rootsdev/gedcomx-js/pull/13 + * + * We put this functionality in a method to be DRY, even though it's short. + * This could easily change in the future for correction and performance. + * + * It could be handy to expose this on GedcomX somewhere so that users of the + * library can use it too. But then we would need to add a way for them to + * easily get the _gedxClass property without being tied to that private + * property name. In other words, a static method such as Person.getClass() + * + * @param {Object} obj + * @param {String} className + * @returns {Boolean} + */ + isInstance: function(obj, className){ + return obj && Object.getPrototypeOf(obj) !== Object.prototype && obj._gedxClass === className; + } + +}; \ No newline at end of file diff --git a/test/Address.js b/test/Address.js index 30fb518..ff4b75b 100644 --- a/test/Address.js +++ b/test/Address.js @@ -78,4 +78,10 @@ describe('Address', function(){ assert.deepEqual(address.toJSON(), data); }); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX.Address(); + var obj2 = GedcomX.Address(obj1); + assert.strictEqual(obj1, obj2); + }); + }); \ No newline at end of file diff --git a/test/Agent.js b/test/Agent.js index c2338d7..5672402 100644 --- a/test/Agent.js +++ b/test/Agent.js @@ -209,4 +209,10 @@ describe('Agent', function(){ assert.deepEqual(agent.toJSON(), data); }); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX.Agent(); + var obj2 = GedcomX.Agent(obj1); + assert.strictEqual(obj1, obj2); + }); + }); \ No newline at end of file diff --git a/test/Attribution.js b/test/Attribution.js index 98c1ef5..0016f63 100644 --- a/test/Attribution.js +++ b/test/Attribution.js @@ -67,4 +67,10 @@ describe('Attribution', function(){ assert.deepEqual(attr.toJSON(), attrData, 'toJSON export does not equal original data.'); }); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX.Attribution(); + var obj2 = GedcomX.Attribution(obj1); + assert.strictEqual(obj1, obj2); + }); + }); \ No newline at end of file diff --git a/test/Conclusion.js b/test/Conclusion.js index 7c17e87..bed3e89 100644 --- a/test/Conclusion.js +++ b/test/Conclusion.js @@ -121,4 +121,10 @@ describe('Conclusion', function(){ assert.deepEqual(conclusion.toJSON(), conclusionData); }); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX.Conclusion(); + var obj2 = GedcomX.Conclusion(obj1); + assert.strictEqual(obj1, obj2); + }); + }); \ No newline at end of file diff --git a/test/Coverage.js b/test/Coverage.js index 81c45c0..c773339 100644 --- a/test/Coverage.js +++ b/test/Coverage.js @@ -54,4 +54,10 @@ describe('Coverage', function(){ assert.deepEqual(coverage.toJSON(), data); }); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX.Coverage(); + var obj2 = GedcomX.Coverage(obj1); + assert.strictEqual(obj1, obj2); + }); + }); \ No newline at end of file diff --git a/test/Date.js b/test/Date.js index 9f63e35..60d7adb 100644 --- a/test/Date.js +++ b/test/Date.js @@ -40,4 +40,10 @@ describe('Date', function(){ assert.deepEqual(date.toJSON(), data); }); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX.Date(); + var obj2 = GedcomX.Date(obj1); + assert.strictEqual(obj1, obj2); + }); + }); \ No newline at end of file diff --git a/test/Document.js b/test/Document.js index 317d01b..66af4af 100644 --- a/test/Document.js +++ b/test/Document.js @@ -69,4 +69,10 @@ describe('Document', function(){ assert.deepEqual(doc.toJSON(), data); }); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX.Document(); + var obj2 = GedcomX.Document(obj1); + assert.strictEqual(obj1, obj2); + }); + }); \ No newline at end of file diff --git a/test/Event.js b/test/Event.js index aac7f8d..8cd3c73 100644 --- a/test/Event.js +++ b/test/Event.js @@ -97,4 +97,10 @@ describe('Event', function(){ assert.deepEqual(event.toJSON(), data); }); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX.Event(); + var obj2 = GedcomX.Event(obj1); + assert.strictEqual(obj1, obj2); + }); + }); \ No newline at end of file diff --git a/test/EventRole.js b/test/EventRole.js index 072f672..5b21dd5 100644 --- a/test/EventRole.js +++ b/test/EventRole.js @@ -55,4 +55,10 @@ describe('EventRole', function(){ assert.deepEqual(role.toJSON(), data); }); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX.EventRole(); + var obj2 = GedcomX.EventRole(obj1); + assert.strictEqual(obj1, obj2); + }); + }); \ No newline at end of file diff --git a/test/EvidenceReference.js b/test/EvidenceReference.js index 8b500d0..755b165 100644 --- a/test/EvidenceReference.js +++ b/test/EvidenceReference.js @@ -42,4 +42,10 @@ describe('EvidenceReference', function(){ assert.deepEqual(er.toJSON(), erData); }); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX.EvidenceReference(); + var obj2 = GedcomX.EvidenceReference(obj1); + assert.strictEqual(obj1, obj2); + }); + }); \ No newline at end of file diff --git a/test/ExtensibleData.js b/test/ExtensibleData.js index 2447d9c..76065f5 100644 --- a/test/ExtensibleData.js +++ b/test/ExtensibleData.js @@ -27,4 +27,10 @@ describe('ExtensibleData', function(){ assert.deepEqual(ed.toJSON(), {id:'newId'}, 'JSON export is incorrect'); }); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX.ExtensibleData(); + var obj2 = GedcomX.ExtensibleData(obj1); + assert.strictEqual(obj1, obj2); + }); + }); \ No newline at end of file diff --git a/test/Fact.js b/test/Fact.js index e94c080..46093ad 100644 --- a/test/Fact.js +++ b/test/Fact.js @@ -105,4 +105,10 @@ describe('Fact', function(){ assert.deepEqual(fact.toJSON(), data); }); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX.Fact(); + var obj2 = GedcomX.Fact(obj1); + assert.strictEqual(obj1, obj2); + }); + }); \ No newline at end of file diff --git a/test/GedcomX.js b/test/GedcomX.js index 1ec1f34..4e57d41 100644 --- a/test/GedcomX.js +++ b/test/GedcomX.js @@ -577,15 +577,10 @@ describe('GedcomX', function(){ assert.jsonSchema(gedx.toJSON(), GedcomXSchema); }); - it('adding Person does not copy', function(){ - var gedx = GedcomX(); - var person = GedcomX.Person({ - id: 'first' - }); - gedx.addPerson(person); - person.setId('second'); - assert.strictEqual(gedx.getPersons()[0], person, 'the added instance is not the same as the original instance'); - assert.deepEqual(gedx.getPersons()[0].toJSON(), person.toJSON(), 'serialization of the added person does not match the original person'); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX(); + var obj2 = GedcomX(obj1); + assert.strictEqual(obj1, obj2); }); }); diff --git a/test/Gender.js b/test/Gender.js index 1a46cb1..9d4b652 100644 --- a/test/Gender.js +++ b/test/Gender.js @@ -51,4 +51,10 @@ describe('Gender', function(){ assert.deepEqual(gender.toJSON(), genderData); }); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX.Gender(); + var obj2 = GedcomX.Gender(obj1); + assert.strictEqual(obj1, obj2); + }); + }); \ No newline at end of file diff --git a/test/Name.js b/test/Name.js index c4eea2b..635a765 100644 --- a/test/Name.js +++ b/test/Name.js @@ -125,4 +125,10 @@ describe('Name', function(){ assert.deepEqual(name.toJSON(), data); }); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX.Name(); + var obj2 = GedcomX.Name(obj1); + assert.strictEqual(obj1, obj2); + }); + }); \ No newline at end of file diff --git a/test/NameForm.js b/test/NameForm.js index 2be9fb9..13d54c5 100644 --- a/test/NameForm.js +++ b/test/NameForm.js @@ -98,4 +98,10 @@ describe('NameForm', function(){ assert.deepEqual(nameForm.toJSON(), data); }); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX.NameForm(); + var obj2 = GedcomX.NameForm(obj1); + assert.strictEqual(obj1, obj2); + }); + }); \ No newline at end of file diff --git a/test/NamePart.js b/test/NamePart.js index 4878ced..28ca25e 100644 --- a/test/NamePart.js +++ b/test/NamePart.js @@ -73,4 +73,10 @@ describe('NamePart', function(){ assert.deepEqual(part.toJSON(), data); }); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX.NamePart(); + var obj2 = GedcomX.NamePart(obj1); + assert.strictEqual(obj1, obj2); + }); + }); \ No newline at end of file diff --git a/test/Note.js b/test/Note.js index 813f1ff..7f9c99d 100644 --- a/test/Note.js +++ b/test/Note.js @@ -78,4 +78,10 @@ describe('Note', function(){ assert.deepEqual(note.toJSON(), noteData); }); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX.Note(); + var obj2 = GedcomX.Note(obj1); + assert.strictEqual(obj1, obj2); + }); + }); \ No newline at end of file diff --git a/test/OnlineAccount.js b/test/OnlineAccount.js index d12376f..2f496e0 100644 --- a/test/OnlineAccount.js +++ b/test/OnlineAccount.js @@ -48,4 +48,10 @@ describe('OnlineAccount', function(){ assert.deepEqual(account.toJSON(), data); }); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX.OnlineAccount(); + var obj2 = GedcomX.OnlineAccount(obj1); + assert.strictEqual(obj1, obj2); + }); + }); \ No newline at end of file diff --git a/test/Person.js b/test/Person.js index 452e9e0..6b3e3c7 100644 --- a/test/Person.js +++ b/test/Person.js @@ -138,4 +138,10 @@ describe('Person', function(){ assert.deepEqual(person.toJSON(), data); }); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX.Person(); + var obj2 = GedcomX.Person(obj1); + assert.strictEqual(obj1, obj2); + }); + }); \ No newline at end of file diff --git a/test/PlaceDescription.js b/test/PlaceDescription.js index a0b81f8..2633809 100644 --- a/test/PlaceDescription.js +++ b/test/PlaceDescription.js @@ -121,4 +121,10 @@ describe('PlaceDescription', function(){ assert.deepEqual(place.toJSON(), data); }); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX.PlaceDescription(); + var obj2 = GedcomX.PlaceDescription(obj1); + assert.strictEqual(obj1, obj2); + }); + }); \ No newline at end of file diff --git a/test/PlaceReference.js b/test/PlaceReference.js index 4a01812..f6b0a76 100644 --- a/test/PlaceReference.js +++ b/test/PlaceReference.js @@ -40,4 +40,10 @@ describe('PlaceReference', function(){ assert.deepEqual(ref.toJSON(), data); }); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX.PlaceReference(); + var obj2 = GedcomX.PlaceReference(obj1); + assert.strictEqual(obj1, obj2); + }); + }); \ No newline at end of file diff --git a/test/Qualifier.js b/test/Qualifier.js index 04865bf..eba0515 100644 --- a/test/Qualifier.js +++ b/test/Qualifier.js @@ -35,4 +35,10 @@ describe('Qualifier', function(){ assert.deepEqual(ref.toJSON(), data); }); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX.Qualifier(); + var obj2 = GedcomX.Qualifier(obj1); + assert.strictEqual(obj1, obj2); + }); + }); \ No newline at end of file diff --git a/test/Relationship.js b/test/Relationship.js index 6839e01..7ea474a 100644 --- a/test/Relationship.js +++ b/test/Relationship.js @@ -85,4 +85,10 @@ describe('Relationship', function(){ assert.deepEqual(relationship.toJSON(), data); }); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX.Relationship(); + var obj2 = GedcomX.Relationship(obj1); + assert.strictEqual(obj1, obj2); + }); + }); \ No newline at end of file diff --git a/test/ResourceReference.js b/test/ResourceReference.js index 174f68f..cbdd518 100644 --- a/test/ResourceReference.js +++ b/test/ResourceReference.js @@ -30,4 +30,10 @@ describe('ResourceReference', function(){ assert.deepEqual(rr.toJSON(), {}); }); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX.ResourceReference(); + var obj2 = GedcomX.ResourceReference(obj1); + assert.strictEqual(obj1, obj2); + }); + }); \ No newline at end of file diff --git a/test/SourceCitation.js b/test/SourceCitation.js index 62e3bbb..c92b512 100644 --- a/test/SourceCitation.js +++ b/test/SourceCitation.js @@ -33,4 +33,10 @@ describe('SourceCitation', function(){ assert.deepEqual(citation.toJSON(), data); }); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX.SourceCitation(); + var obj2 = GedcomX.SourceCitation(obj1); + assert.strictEqual(obj1, obj2); + }); + }); \ No newline at end of file diff --git a/test/SourceDescription.js b/test/SourceDescription.js index 53a4c16..f6194da 100644 --- a/test/SourceDescription.js +++ b/test/SourceDescription.js @@ -280,4 +280,10 @@ describe('SourceDescription', function(){ assert.deepEqual(description.toJSON(), fullJSON); }); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX.SourceDescription(); + var obj2 = GedcomX.SourceDescription(obj1); + assert.strictEqual(obj1, obj2); + }); + }); \ No newline at end of file diff --git a/test/SourceReference.js b/test/SourceReference.js index 9e4c0c6..0449b74 100644 --- a/test/SourceReference.js +++ b/test/SourceReference.js @@ -58,4 +58,10 @@ describe('SourceReference', function(){ assert.deepEqual(ref.toJSON(), refData); }); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX.SourceReference(); + var obj2 = GedcomX.SourceReference(obj1); + assert.strictEqual(obj1, obj2); + }); + }); \ No newline at end of file diff --git a/test/Subject.js b/test/Subject.js index 0d5cc50..f2bb835 100644 --- a/test/Subject.js +++ b/test/Subject.js @@ -129,4 +129,10 @@ describe('Subject', function(){ assert.deepEqual(subjectData, subject.toJSON()); }); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX.Subject(); + var obj2 = GedcomX.Subject(obj1); + assert.strictEqual(obj1, obj2); + }); + }); \ No newline at end of file diff --git a/test/TextValue.js b/test/TextValue.js index 0386fae..16c41fa 100644 --- a/test/TextValue.js +++ b/test/TextValue.js @@ -35,4 +35,10 @@ describe('TextValue', function(){ assert.deepEqual(value.toJSON(), data); }); + it('constructor does not copy instances', function(){ + var obj1 = GedcomX.TextValue(); + var obj2 = GedcomX.TextValue(obj1); + assert.strictEqual(obj1, obj2); + }); + }); \ No newline at end of file