Skip to content

Commit 396fb90

Browse files
committed
Make the whole data model immutable
1 parent 64bdf05 commit 396fb90

20 files changed

+124
-1108
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,41 @@ at the heart of the [Wikibase software](http://wikiba.se/).
1111
### 3.0.0 (alpha)
1212

1313
* Removed cloning from `MultiTerm.getTexts`.
14+
* The whole data model is now immutable:
15+
** Removed `Claim.setMainSnak`
16+
** Removed `Claim.setQualifiers`
17+
** Removed `Entity.setFingerprint`
18+
** Removed `Fingerprint.removeAliases`
19+
** Removed `Fingerprint.removeAliasesFor`
20+
** Removed `Fingerprint.removeDescription`
21+
** Removed `Fingerprint.removeDescriptionFor`
22+
** Removed `Fingerprint.removeLabel`
23+
** Removed `Fingerprint.removeLabelFor`
24+
** Removed `Fingerprint.setAliases`
25+
** Removed `Fingerprint.setDescription`
26+
** Removed `Fingerprint.setLabel`
27+
** Made `Group.setItemContainer` private
28+
** Removed `GroupableCollection.addItem`
29+
** Removed `GroupableCollection.removeItem`
30+
** Removed `Item.addSiteLink`
31+
** Removed `Item.addStatement`
32+
** Removed `Item.removeSiteLink`
33+
** Removed `Item.removeStatement`
34+
** Removed `MultiTerm.setLanguageCode`
35+
** Removed `MultiTerm.setTexts`
36+
** Removed `Property.addStatement`
37+
** Removed `Property.removeStatement`
38+
** Removed `SiteLink.setBadges`
39+
** Removed `SnakList.getValidMoveIndices`
40+
** Removed `SnakList.merge`
41+
** Removed `SnakList.move`
42+
** Removed `SnakList.moveDown`
43+
** Removed `SnakList.moveUp`
44+
** Removed `Statement.setClaim`
45+
** Made `Statement.setRank` private
46+
** Removed `Statement.setReferences`
47+
** Removed `Term.setLanguageCode`
48+
** Removed `Term.setText`
1449

1550
### 2.0.1 (2016-01-27)
1651

src/Claim.js

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,20 @@
1414
* @param {wikibase.datamodel.SnakList|null} [qualifiers=new wikibase.datamodel.SnakList()]
1515
* @param {string|null} [guid=null] The Global Unique Identifier of this Claim. Can be null if this
1616
* is a new Claim, not yet stored in the database and associated with some entity.
17+
*
18+
* @throws {Error} if parameter is not a Snak instance.
19+
* @throws {Error} if parameter is not a SnakList instance.
1720
*/
1821
var SELF = wb.datamodel.Claim = function WbDataModelClaim( mainSnak, qualifiers, guid ) {
19-
this.setMainSnak( mainSnak );
20-
this.setQualifiers( qualifiers || new wb.datamodel.SnakList() );
22+
if( !( mainSnak instanceof wb.datamodel.Snak ) ) {
23+
throw new Error( 'Main snak needs to be a Snak instance' );
24+
}
25+
if( qualifiers && !( qualifiers instanceof wb.datamodel.SnakList ) ) {
26+
throw new Error( 'Qualifiers have to be a SnakList object' );
27+
}
28+
29+
this._mainSnak = mainSnak;
30+
this._qualifiers = qualifiers || new wb.datamodel.SnakList();
2131
this._guid = guid || null;
2232
};
2333

@@ -59,39 +69,13 @@ $.extend( SELF.prototype, {
5969
return this._mainSnak;
6070
},
6171

62-
/**
63-
* Overwrites the current main Snak.
64-
*
65-
* @param {wikibase.datamodel.Snak} mainSnak
66-
*
67-
* @throws {Error} if parameter is not a Snak instance.
68-
*/
69-
setMainSnak: function( mainSnak ) {
70-
if( !( mainSnak instanceof wb.datamodel.Snak ) ) {
71-
throw new Error( 'Main snak needs to be a Snak instance' );
72-
}
73-
this._mainSnak = mainSnak;
74-
},
75-
7672
/**
7773
* @return {wikibase.datamodel.SnakList}
7874
*/
7975
getQualifiers: function() {
8076
return this._qualifiers;
8177
},
8278

83-
/**
84-
* @param {wikibase.datamodel.SnakList} qualifiers
85-
*
86-
* @throws {Error} if parameter is not a SnakList instance.
87-
*/
88-
setQualifiers: function( qualifiers ) {
89-
if( !( qualifiers instanceof wb.datamodel.SnakList ) ) {
90-
throw new Error( 'Qualifiers have to be a SnakList object' );
91-
}
92-
this._qualifiers = qualifiers;
93-
},
94-
9579
/**
9680
* @param {*} claim
9781
* @return {boolean}

src/Entity.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,6 @@ $.extend( SELF.prototype, {
5151
return this._fingerprint;
5252
},
5353

54-
/**
55-
* @param {wikibase.datamodel.Fingerprint} fingerprint
56-
*/
57-
setFingerprint: function( fingerprint ) {
58-
this._fingerprint = fingerprint;
59-
},
60-
6154
/**
6255
* Returns what type of Entity this is.
6356
*

src/Fingerprint.js

Lines changed: 0 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -87,33 +87,6 @@ $.extend( SELF.prototype, {
8787
return this._labels.hasItemForKey( languageCode );
8888
},
8989

90-
/**
91-
* @param {string} languageCode
92-
* @param {wikibase.datamodel.Term} term
93-
*/
94-
setLabel: function( languageCode, term ) {
95-
if ( term.getText() === '' ) {
96-
this._labels.removeItemByKey( languageCode );
97-
} else {
98-
this._labels.setItem( languageCode, term );
99-
}
100-
},
101-
102-
/**
103-
* @param {string} languageCode
104-
* @param {wikibase.datamodel.Term} label
105-
*/
106-
removeLabel: function( languageCode, label ) {
107-
this._labels.removeItem( languageCode, label );
108-
},
109-
110-
/**
111-
* @param {string} languageCode
112-
*/
113-
removeLabelFor: function( languageCode ) {
114-
this._labels.removeItemByKey( languageCode );
115-
},
116-
11790
/**
11891
* @return {wikibase.datamodel.TermMap}
11992
*/
@@ -146,33 +119,6 @@ $.extend( SELF.prototype, {
146119
return this._descriptions.hasItemForKey( languageCode );
147120
},
148121

149-
/**
150-
* @param {string} languageCode
151-
* @param {wikibase.datamodel.Term} term
152-
*/
153-
setDescription: function( languageCode, term ) {
154-
if ( term.getText() === '' ) {
155-
this._descriptions.removeItemByKey( languageCode );
156-
} else {
157-
this._descriptions.setItem( languageCode, term );
158-
}
159-
},
160-
161-
/**
162-
* @param {string} languageCode
163-
* @param {wikibase.datamodel.Term} description
164-
*/
165-
removeDescription: function( languageCode, description ) {
166-
this._descriptions.removeItem( languageCode, description );
167-
},
168-
169-
/**
170-
* @param {string} languageCode
171-
*/
172-
removeDescriptionFor: function( languageCode ) {
173-
this._descriptions.removeItemByKey( languageCode );
174-
},
175-
176122
/**
177123
* @return {wikibase.datamodel.MultiTermMap}
178124
*/
@@ -205,60 +151,6 @@ $.extend( SELF.prototype, {
205151
return this._aliases.hasItemForKey( languageCode );
206152
},
207153

208-
/**
209-
* @param {string|wikibase.datamodel.MultiTermMap} languageCodeOrAliases
210-
* @param {wikibase.datamodel.MultiTerm} [aliases]
211-
*
212-
* @throws {Error} when passing a MultiTerm without a language code.
213-
* @throws {Error} when passing a MultiTermMap with a language code.
214-
* @throws {Error} when neither passing a MultiTerm nor a MultiTermMap object.
215-
*/
216-
setAliases: function( languageCodeOrAliases, aliases ) {
217-
var languageCode;
218-
219-
if( typeof languageCodeOrAliases === 'string' ) {
220-
languageCode = languageCodeOrAliases;
221-
} else {
222-
aliases = languageCodeOrAliases;
223-
}
224-
225-
if( aliases instanceof wb.datamodel.MultiTerm ) {
226-
if( !languageCode ) {
227-
throw new Error( 'Language code the wb.datamodel.MultiTerm object should be set '
228-
+ 'for needs to be specified' );
229-
}
230-
if ( aliases.isEmpty() ) {
231-
this._aliases.removeItemByKey( languageCode );
232-
} else {
233-
this._aliases.setItem( languageCode, aliases );
234-
}
235-
} else if( aliases instanceof wb.datamodel.MultiTermMap ) {
236-
if( languageCode ) {
237-
throw new Error( 'Unable to handle language code when setting a '
238-
+ 'wb.datamodel.MultiTermMap' );
239-
}
240-
this._aliases = aliases;
241-
} else {
242-
throw new Error( 'Aliases need to be specified as wb.datamodel.MultiTerm or '
243-
+ 'wb.datamodel.MultiTermMap instance' );
244-
}
245-
},
246-
247-
/**
248-
* @param {string} languageCode
249-
* @param {wikibase.datamodel.MultiTerm} aliases
250-
*/
251-
removeAliases: function( languageCode, aliases ) {
252-
this._aliases.removeItem( languageCode, aliases );
253-
},
254-
255-
/**
256-
* @param {string} languageCode
257-
*/
258-
removeAliasesFor: function( languageCode ) {
259-
this._aliases.removeItemByKey( languageCode );
260-
},
261-
262154
/**
263155
* @return {boolean}
264156
*/

src/Group.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ $.extend( SELF.prototype, {
7676

7777
/**
7878
* @param {wikibase.datamodel.GroupableCollection} groupableCollection
79-
*
8079
* @throws {Error} when passed GroupableCollection instance contains an item whose key does not
8180
* match the key registered with the Group instance.
81+
* @private
8282
*/
8383
setItemContainer: function( groupableCollection ) {
8484
if( !( groupableCollection instanceof wb.datamodel.GroupableCollection ) ) {

src/GroupableCollection.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,6 @@ $.extend( SELF.prototype, {
3131
*/
3232
hasItem: util.abstractMember,
3333

34-
/**
35-
* Adds an item to the collection.
36-
* @abstract
37-
*
38-
* @param {*} item
39-
*/
40-
addItem: util.abstractMember,
41-
42-
/**
43-
* Removes an item from the collection.
44-
* @abstract
45-
*
46-
* @param {*} item
47-
*/
48-
removeItem: util.abstractMember,
49-
5034
/**
5135
* Returns whether the collection contains any items.
5236
* @abstract

src/Item.js

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -62,41 +62,13 @@ var SELF = wb.datamodel.Item = util.inherit(
6262
return this._siteLinkSet;
6363
},
6464

65-
/**
66-
* @param {wikibase.datamodel.SiteLink} siteLink
67-
*/
68-
addSiteLink: function( siteLink ) {
69-
this._siteLinkSet.setSiteLink( siteLink );
70-
},
71-
72-
/**
73-
* @param {wikibase.datamodel.SiteLink} siteLink
74-
*/
75-
removeSiteLink: function( siteLink ) {
76-
this._siteLinkSet.removeSiteLink( siteLink );
77-
},
78-
7965
/**
8066
* @return {wikibase.datamodel.StatementGroupSet}
8167
*/
8268
getStatements: function() {
8369
return this._statementGroupSet;
8470
},
8571

86-
/**
87-
* @param {wikibase.datamodel.Statement} statement
88-
*/
89-
addStatement: function( statement ) {
90-
this._statementGroupSet.addStatement( statement );
91-
},
92-
93-
/**
94-
* @param {wikibase.datamodel.Statement} statement
95-
*/
96-
removeStatement: function( statement ) {
97-
this._statementGroupSet.removeStatement( statement );
98-
},
99-
10072
/**
10173
* @return {boolean}
10274
*/

src/MultiTerm.js

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,20 @@
1212
*
1313
* @param {string} languageCode
1414
* @param {string[]} texts
15+
*
16+
* @throws {Error} when the language code is not a string or empty.
17+
* @throws {Error} when texts is not an array.
1518
*/
1619
var SELF = wb.datamodel.MultiTerm = function WbDataModelMultiTerm( languageCode, texts ) {
17-
this.setLanguageCode( languageCode );
18-
this.setTexts( texts );
20+
if( typeof languageCode !== 'string' || languageCode === '' ) {
21+
throw new Error( 'Language code has to be a non-empty string' );
22+
}
23+
if( !$.isArray( texts ) ) {
24+
throw new Error( 'texts needs to be an array of strings' );
25+
}
26+
27+
this._languageCode = languageCode;
28+
this._texts = texts;
1929
};
2030

2131
$.extend( SELF.prototype, {
@@ -38,37 +48,13 @@ $.extend( SELF.prototype, {
3848
return this._languageCode;
3949
},
4050

41-
/**
42-
* @param {string} languageCode
43-
*
44-
* @throws {Error} when the language code is not a string or empty.
45-
*/
46-
setLanguageCode: function( languageCode ) {
47-
if( typeof languageCode !== 'string' || languageCode === '' ) {
48-
throw new Error( 'Language code has to be a non-empty string' );
49-
}
50-
this._languageCode = languageCode;
51-
},
52-
5351
/**
5452
* @return {string[]}
5553
*/
5654
getTexts: function() {
5755
return this._texts;
5856
},
5957

60-
/**
61-
* @param {string[]} texts
62-
*
63-
* @throws {Error} when texts is not an array.
64-
*/
65-
setTexts: function( texts ) {
66-
if( !$.isArray( texts ) ) {
67-
throw new Error( 'texts needs to be an array of strings' );
68-
}
69-
this._texts = texts;
70-
},
71-
7258
/**
7359
* @param {*} multiTerm
7460
* @return {boolean}

0 commit comments

Comments
 (0)