Skip to content

Commit 3211118

Browse files
committed
Make the whole data model immutable
1 parent 721323a commit 3211118

25 files changed

+148
-1626
lines changed

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,56 @@ at the heart of the [Wikibase software](http://wikiba.se/).
88

99
## Release notes
1010

11+
### 3.0.0 (dev)
12+
13+
The whole data model is now immutable:
14+
* Removed `Claim.setMainSnak`
15+
* Removed `Claim.setQualifiers`
16+
* Removed `Entity.setFingerprint`
17+
* Removed `Fingerprint.removeAliases`
18+
* Removed `Fingerprint.removeAliasesFor`
19+
* Removed `Fingerprint.removeDescription`
20+
* Removed `Fingerprint.removeDescriptionFor`
21+
* Removed `Fingerprint.removeLabel`
22+
* Removed `Fingerprint.removeLabelFor`
23+
* Removed `Fingerprint.setAliases`
24+
* Removed `Fingerprint.setDescription`
25+
* Removed `Fingerprint.setLabel`
26+
* Removed `Group.addItem`
27+
* Removed `Group.removeItem`
28+
* Made `Group.setItemContainer` private
29+
* Removed `GroupableCollection.addItem`
30+
* Removed `GroupableCollection.removeItem`
31+
* Removed `Item.addSiteLink`
32+
* Removed `Item.addStatement`
33+
* Removed `Item.removeSiteLink`
34+
* Removed `Item.removeStatement`
35+
* Removed `List.addItem`
36+
* Removed `List.removeItem`
37+
* Removed `Map.addItem`
38+
* Removed `Map.removeItem`
39+
* Removed `Map.removeItemByKey`
40+
* Removed `Map.setItem`
41+
* Removed `MultiTerm.setLanguageCode`
42+
* Removed `MultiTerm.setTexts`
43+
* Removed `Property.addStatement`
44+
* Removed `Property.removeStatement`
45+
* Removed `Set.addItem`
46+
* Removed `Set.removeItem`
47+
* Removed `Set.removeItemByKey`
48+
* Removed `Set.setItem`
49+
* Removed `SiteLink.setBadges`
50+
* Removed `SnakList.getValidMoveIndices`
51+
* Removed `SnakList.merge`
52+
* Removed `SnakList.move`
53+
* Removed `SnakList.moveDown`
54+
* Removed `SnakList.moveUp`
55+
* Removed `Statement.setClaim`
56+
* Made `Statement.setRank` private
57+
* Removed `Statement.setReferences`
58+
* Removed `Term.setLanguageCode`
59+
* Removed `Term.setText`
60+
1161
### 2.0.0 (2016-01-12)
1262

1363
#### Breaking changes

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 & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -87,29 +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-
this._labels.setItem( languageCode, term );
96-
},
97-
98-
/**
99-
* @param {string} languageCode
100-
* @param {wikibase.datamodel.Term} label
101-
*/
102-
removeLabel: function( languageCode, label ) {
103-
this._labels.removeItem( languageCode, label );
104-
},
105-
106-
/**
107-
* @param {string} languageCode
108-
*/
109-
removeLabelFor: function( languageCode ) {
110-
this._labels.removeItemByKey( languageCode );
111-
},
112-
11390
/**
11491
* @return {wikibase.datamodel.TermMap}
11592
*/
@@ -142,29 +119,6 @@ $.extend( SELF.prototype, {
142119
return this._descriptions.hasItemForKey( languageCode );
143120
},
144121

145-
/**
146-
* @param {string} languageCode
147-
* @param {wikibase.datamodel.Term} term
148-
*/
149-
setDescription: function( languageCode, term ) {
150-
this._descriptions.setItem( languageCode, term );
151-
},
152-
153-
/**
154-
* @param {string} languageCode
155-
* @param {wikibase.datamodel.Term} description
156-
*/
157-
removeDescription: function( languageCode, description ) {
158-
this._descriptions.removeItem( languageCode, description );
159-
},
160-
161-
/**
162-
* @param {string} languageCode
163-
*/
164-
removeDescriptionFor: function( languageCode ) {
165-
this._descriptions.removeItemByKey( languageCode );
166-
},
167-
168122
/**
169123
* @return {wikibase.datamodel.MultiTermMap}
170124
*/
@@ -197,56 +151,6 @@ $.extend( SELF.prototype, {
197151
return this._aliases.hasItemForKey( languageCode );
198152
},
199153

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

src/Group.js

Lines changed: 1 addition & 24 deletions
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 ) ) {
@@ -114,29 +114,6 @@ $.extend( SELF.prototype, {
114114
return this._groupableCollection.hasItem( item );
115115
},
116116

117-
/**
118-
* @param {*} item
119-
*
120-
* @throws {Error} when trying to add an item whose key does not match the key registered with
121-
* the Group instance.
122-
*/
123-
addItem: function( item ) {
124-
if( this._groupableCollection.getItemKey( item ) !== this._key ) {
125-
throw new Error(
126-
'Mismatching key: Expected ' + this._key + ', received '
127-
+ this._groupableCollection.getItemKey( item )
128-
);
129-
}
130-
this._groupableCollection.addItem( item );
131-
},
132-
133-
/**
134-
* @param {*} item
135-
*/
136-
removeItem: function( item ) {
137-
this._groupableCollection.removeItem( item );
138-
},
139-
140117
/**
141118
* @return {boolean}
142119
*/

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/List.js

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -89,34 +89,6 @@ var SELF = wb.datamodel.List = util.inherit(
8989
return false;
9090
},
9191

92-
/**
93-
* @inheritdoc
94-
*/
95-
addItem: function( item ) {
96-
this._assertIsItem( item );
97-
98-
this._items.push( item );
99-
this.length++;
100-
},
101-
102-
/**
103-
* @inheritdoc
104-
*
105-
* @throws {Error} when trying to remove a claim which is not registered.
106-
*/
107-
removeItem: function( item ) {
108-
this._assertIsItem( item );
109-
110-
for( var i = 0; i < this._items.length; i++ ) {
111-
if( this._items[i].equals( item ) ) {
112-
this._items.splice( i, 1 );
113-
this.length--;
114-
return;
115-
}
116-
}
117-
throw new Error( 'Trying to remove a non-existing claim' );
118-
},
119-
12092
/**
12193
* @inheritdoc
12294
*/

0 commit comments

Comments
 (0)