Skip to content

Use CommonJS modules instead of global namespaces #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
},
"globals": {
"dataValues": false,
"util": false,
"wikibase": false
"util": false
},
"rules": {
"computed-property-spacing": "off",
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ the corresponding serializer, and send back to the API.

## Release notes

### 6.0.0 (dev)
* Using CommonJS modules instead of global namespaces for all files

### 5.1.0 (2019-10-01)
* Added `index.js` exporting all public data model parts

Expand Down
17 changes: 0 additions & 17 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,18 @@ module.exports = function ( config ) {
'node_modules/wikibase-data-values/src/dataValues.js',
'node_modules/wikibase-data-values/lib/util/util.inherit.js',
'node_modules/wikibase-data-values/src/DataValue.js',
'src/__namespace.js',
'src/Claim.js',
'src/Entity.js',
'src/Fingerprint.js',
'src/GroupableCollection.js',
'src/Group.js',
'src/Map.js',
'src/MultiTerm.js',
'src/Reference.js',
'src/SiteLink.js',
'src/Snak.js',
'src/Statement.js',
'src/Term.js',
'src/Set.js',
'src/List.js',
'node_modules/wikibase-data-values/lib/globeCoordinate/globeCoordinate.js',
'node_modules/wikibase-data-values/lib/globeCoordinate/globeCoordinate.GlobeCoordinate.js',
'node_modules/wikibase-data-values/src/valueFormatters/valueFormatters.js',
'node_modules/wikibase-data-values/src/valueParsers/valueParsers.js',
'node_modules/wikibase-data-values/src/dataValues.js',
'node_modules/wikibase-data-values/src/*.js',
'node_modules/wikibase-data-values/src/values/*.js',
'src/*.js',
'tests/*.js'
],
port: 9876,

preprocessors: {
'src/**/*.js': [ 'webpack' ],
'tests/**/*.tests.js': [ 'webpack' ]
},

Expand Down
37 changes: 21 additions & 16 deletions src/Claim.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
( function( wb, $ ) {
( function( $ ) {
'use strict';

var Snak = require( './Snak.js' ),
SnakList = require( './SnakList.js' );

/**
* Object featuring a main snak and a list of qualifiers.
* @class wikibase.datamodel.Claim
* @class Claim
* @since 0.3
* @license GPL-2.0+
* @author Daniel Werner < daniel.a.r.werner@gmail.com >
*
* @constructor
*
* @param {wikibase.datamodel.Snak} mainSnak
* @param {wikibase.datamodel.SnakList|null} [qualifiers=new wikibase.datamodel.SnakList()]
* @param {Snak} mainSnak
* @param {SnakList|null} [qualifiers=new SnakList()]
* @param {string|null} [guid=null] The Global Unique Identifier of this Claim. Can be null if this
* is a new Claim, not yet stored in the database and associated with some entity.
*/
var SELF = wb.datamodel.Claim = function WbDataModelClaim( mainSnak, qualifiers, guid ) {
var SELF = function WbDataModelClaim( mainSnak, qualifiers, guid ) {
this.setMainSnak( mainSnak );
this.setQualifiers( qualifiers || new wb.datamodel.SnakList() );
this.setQualifiers( qualifiers || new SnakList() );
this._guid = guid || null;
};

/**
* @class wikibase.datamodel.Claim
* @class Claim
*/
$.extend( SELF.prototype, {
/**
* @property {wikibase.datamodel.Snak}
* @property {Snak}
* @private
*/
_mainSnak: null,

/**
* @property {wikibase.datamodel.SnakList}
* @property {SnakList}
* @private
*/
_qualifiers: null,
Expand All @@ -56,7 +59,7 @@ $.extend( SELF.prototype, {
/**
* Returns the main Snak.
*
* @return {wikibase.datamodel.Snak}
* @return {Snak}
*/
getMainSnak: function() {
return this._mainSnak;
Expand All @@ -65,31 +68,31 @@ $.extend( SELF.prototype, {
/**
* Overwrites the current main Snak.
*
* @param {wikibase.datamodel.Snak} mainSnak
* @param {Snak} mainSnak
*
* @throws {Error} if parameter is not a Snak instance.
*/
setMainSnak: function( mainSnak ) {
if( !( mainSnak instanceof wb.datamodel.Snak ) ) {
if( !( mainSnak instanceof Snak ) ) {
throw new Error( 'Main snak needs to be a Snak instance' );
}
this._mainSnak = mainSnak;
},

/**
* @return {wikibase.datamodel.SnakList}
* @return {SnakList}
*/
getQualifiers: function() {
return this._qualifiers;
},

/**
* @param {wikibase.datamodel.SnakList} qualifiers
* @param {SnakList} qualifiers
*
* @throws {Error} if parameter is not a SnakList instance.
*/
setQualifiers: function( qualifiers ) {
if( !( qualifiers instanceof wb.datamodel.SnakList ) ) {
if( !( qualifiers instanceof SnakList ) ) {
throw new Error( 'Qualifiers have to be a SnakList object' );
}
this._qualifiers = qualifiers;
Expand All @@ -107,4 +110,6 @@ $.extend( SELF.prototype, {
}
} );

}( wikibase, jQuery ) );
module.exports = SELF;

}( jQuery ) );
12 changes: 7 additions & 5 deletions src/Entity.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
( function( wb, $ ) {
( function( $ ) {
'use strict';

/**
* Abstract Entity base class featuring an id and a fingerprint.
* @class wikibase.datamodel.Entity
* @class Entity
* @abstract
* @since 0.3
* @license GPL-2.0+
Expand All @@ -13,7 +13,7 @@
*
* @throws {Error} when trying to instantiate since Entity is abstract.
*/
var SELF = wb.datamodel.Entity = function WbDataModelEntity() {
var SELF = function WbDataModelEntity() {
throw new Error( 'Cannot construct abstract Entity object' );
};

Expand All @@ -25,7 +25,7 @@ var SELF = wb.datamodel.Entity = function WbDataModelEntity() {
SELF.TYPE = null;

/**
* @class wikibase.datamodel.Entity
* @class Entity
*/
$.extend( SELF.prototype, {
/**
Expand Down Expand Up @@ -66,4 +66,6 @@ $.extend( SELF.prototype, {
equals: util.abstractMember
} );

}( wikibase, jQuery ) );
module.exports = SELF;

}( jQuery ) );
22 changes: 12 additions & 10 deletions src/EntityId.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
( function( wb, dv, util ) {
( function( dv, util ) {
'use strict';

var PARENT = dv.DataValue;

/**
* EntityId data value.
* @class wikibase.datamodel.EntityId
* @class EntityId
* @extends dataValues.DataValue
* @since 0.3
* @license GPL-2.0+
Expand All @@ -18,7 +18,7 @@ var PARENT = dv.DataValue;
*
* @throws {Error} if a required parameter is not specified properly.
*/
wb.datamodel.EntityId = util.inherit(
var SELF = util.inherit(
'WbDataModelEntityId',
PARENT,
function( serialization ) {
Expand Down Expand Up @@ -55,7 +55,7 @@ wb.datamodel.EntityId = util.inherit(
/**
* @inheritdoc
*
* @return {wikibase.datamodel.EntityId}
* @return {EntityId}
*/
getValue: function() {
return this;
Expand All @@ -75,18 +75,20 @@ wb.datamodel.EntityId = util.inherit(
* @inheritdoc
* @static
*
* @return {wikibase.datamodel.EntityId}
* @return {EntityId}
*/
wb.datamodel.EntityId.newFromJSON = function( json ) {
return new wb.datamodel.EntityId( json.id );
SELF.newFromJSON = function( json ) {
return new SELF( json.id );
};

/**
* @inheritdoc
* @property {string} [TYPE='wikibase-entityid']
*/
wb.datamodel.EntityId.TYPE = 'wikibase-entityid';
SELF.TYPE = 'wikibase-entityid';

dv.registerDataValue( wb.datamodel.EntityId );
dv.registerDataValue( SELF );

}( wikibase, dataValues, util ) );
module.exports = SELF;

}( dataValues, util ) );
Loading