Broke out a base data adapter
This should allow us to create a basic interface that all adapters must follow.
This commit is contained in:
parent
08ac13d510
commit
114732ec25
25
dist/js/select2.amd.full.js
vendored
25
dist/js/select2.amd.full.js
vendored
@ -136,17 +136,38 @@ define('select2/utils',[], function () {
|
||||
return Utils;
|
||||
});
|
||||
|
||||
define('select2/data/base',[
|
||||
'../utils'
|
||||
], function (Utils) {
|
||||
function BaseAdapter ($element, options) {
|
||||
BaseAdapter.__super__.constructor.call(this);
|
||||
}
|
||||
|
||||
Utils.Extend(BaseAdapter, Utils.Observable);
|
||||
|
||||
BaseAdapter.prototype.current = function (callback) {
|
||||
throw new Error("The `current` method must be defined in child classes.");
|
||||
}
|
||||
|
||||
BaseAdapter.prototype.query = function (params, callback) {
|
||||
throw new Error("The `query` method must be defined in child classes.");
|
||||
}
|
||||
|
||||
return BaseAdapter;
|
||||
});
|
||||
|
||||
define('select2/data/select',[
|
||||
'./base',
|
||||
'../utils',
|
||||
'jquery'
|
||||
], function (Utils, $) {
|
||||
], function (BaseAdapter, Utils, $) {
|
||||
function SelectAdapter ($element, options) {
|
||||
this.$element = $element;
|
||||
|
||||
SelectAdapter.__super__.constructor.call(this);
|
||||
}
|
||||
|
||||
Utils.Extend(SelectAdapter, Utils.Observable);
|
||||
Utils.Extend(SelectAdapter, BaseAdapter);
|
||||
|
||||
SelectAdapter.prototype.current = function (callback) {
|
||||
var data = [];
|
||||
|
25
dist/js/select2.amd.js
vendored
25
dist/js/select2.amd.js
vendored
@ -136,17 +136,38 @@ define('select2/utils',[], function () {
|
||||
return Utils;
|
||||
});
|
||||
|
||||
define('select2/data/base',[
|
||||
'../utils'
|
||||
], function (Utils) {
|
||||
function BaseAdapter ($element, options) {
|
||||
BaseAdapter.__super__.constructor.call(this);
|
||||
}
|
||||
|
||||
Utils.Extend(BaseAdapter, Utils.Observable);
|
||||
|
||||
BaseAdapter.prototype.current = function (callback) {
|
||||
throw new Error("The `current` method must be defined in child classes.");
|
||||
}
|
||||
|
||||
BaseAdapter.prototype.query = function (params, callback) {
|
||||
throw new Error("The `query` method must be defined in child classes.");
|
||||
}
|
||||
|
||||
return BaseAdapter;
|
||||
});
|
||||
|
||||
define('select2/data/select',[
|
||||
'./base',
|
||||
'../utils',
|
||||
'jquery'
|
||||
], function (Utils, $) {
|
||||
], function (BaseAdapter, Utils, $) {
|
||||
function SelectAdapter ($element, options) {
|
||||
this.$element = $element;
|
||||
|
||||
SelectAdapter.__super__.constructor.call(this);
|
||||
}
|
||||
|
||||
Utils.Extend(SelectAdapter, Utils.Observable);
|
||||
Utils.Extend(SelectAdapter, BaseAdapter);
|
||||
|
||||
SelectAdapter.prototype.current = function (callback) {
|
||||
var data = [];
|
||||
|
25
dist/js/select2.full.js
vendored
25
dist/js/select2.full.js
vendored
@ -9673,17 +9673,38 @@ define('select2/utils',[], function () {
|
||||
return Utils;
|
||||
});
|
||||
|
||||
define('select2/data/base',[
|
||||
'../utils'
|
||||
], function (Utils) {
|
||||
function BaseAdapter ($element, options) {
|
||||
BaseAdapter.__super__.constructor.call(this);
|
||||
}
|
||||
|
||||
Utils.Extend(BaseAdapter, Utils.Observable);
|
||||
|
||||
BaseAdapter.prototype.current = function (callback) {
|
||||
throw new Error("The `current` method must be defined in child classes.");
|
||||
}
|
||||
|
||||
BaseAdapter.prototype.query = function (params, callback) {
|
||||
throw new Error("The `query` method must be defined in child classes.");
|
||||
}
|
||||
|
||||
return BaseAdapter;
|
||||
});
|
||||
|
||||
define('select2/data/select',[
|
||||
'./base',
|
||||
'../utils',
|
||||
'jquery'
|
||||
], function (Utils, $) {
|
||||
], function (BaseAdapter, Utils, $) {
|
||||
function SelectAdapter ($element, options) {
|
||||
this.$element = $element;
|
||||
|
||||
SelectAdapter.__super__.constructor.call(this);
|
||||
}
|
||||
|
||||
Utils.Extend(SelectAdapter, Utils.Observable);
|
||||
Utils.Extend(SelectAdapter, BaseAdapter);
|
||||
|
||||
SelectAdapter.prototype.current = function (callback) {
|
||||
var data = [];
|
||||
|
25
dist/js/select2.js
vendored
25
dist/js/select2.js
vendored
@ -564,17 +564,38 @@ define('select2/utils',[], function () {
|
||||
return Utils;
|
||||
});
|
||||
|
||||
define('select2/data/base',[
|
||||
'../utils'
|
||||
], function (Utils) {
|
||||
function BaseAdapter ($element, options) {
|
||||
BaseAdapter.__super__.constructor.call(this);
|
||||
}
|
||||
|
||||
Utils.Extend(BaseAdapter, Utils.Observable);
|
||||
|
||||
BaseAdapter.prototype.current = function (callback) {
|
||||
throw new Error("The `current` method must be defined in child classes.");
|
||||
}
|
||||
|
||||
BaseAdapter.prototype.query = function (params, callback) {
|
||||
throw new Error("The `query` method must be defined in child classes.");
|
||||
}
|
||||
|
||||
return BaseAdapter;
|
||||
});
|
||||
|
||||
define('select2/data/select',[
|
||||
'./base',
|
||||
'../utils',
|
||||
'jquery'
|
||||
], function (Utils, $) {
|
||||
], function (BaseAdapter, Utils, $) {
|
||||
function SelectAdapter ($element, options) {
|
||||
this.$element = $element;
|
||||
|
||||
SelectAdapter.__super__.constructor.call(this);
|
||||
}
|
||||
|
||||
Utils.Extend(SelectAdapter, Utils.Observable);
|
||||
Utils.Extend(SelectAdapter, BaseAdapter);
|
||||
|
||||
SelectAdapter.prototype.current = function (callback) {
|
||||
var data = [];
|
||||
|
19
src/js/select2/data/base.js
vendored
Normal file
19
src/js/select2/data/base.js
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
define([
|
||||
'../utils'
|
||||
], function (Utils) {
|
||||
function BaseAdapter ($element, options) {
|
||||
BaseAdapter.__super__.constructor.call(this);
|
||||
}
|
||||
|
||||
Utils.Extend(BaseAdapter, Utils.Observable);
|
||||
|
||||
BaseAdapter.prototype.current = function (callback) {
|
||||
throw new Error("The `current` method must be defined in child classes.");
|
||||
}
|
||||
|
||||
BaseAdapter.prototype.query = function (params, callback) {
|
||||
throw new Error("The `query` method must be defined in child classes.");
|
||||
}
|
||||
|
||||
return BaseAdapter;
|
||||
});
|
5
src/js/select2/data/select.js
vendored
5
src/js/select2/data/select.js
vendored
@ -1,14 +1,15 @@
|
||||
define([
|
||||
'./base',
|
||||
'../utils',
|
||||
'jquery'
|
||||
], function (Utils, $) {
|
||||
], function (BaseAdapter, Utils, $) {
|
||||
function SelectAdapter ($element, options) {
|
||||
this.$element = $element;
|
||||
|
||||
SelectAdapter.__super__.constructor.call(this);
|
||||
}
|
||||
|
||||
Utils.Extend(SelectAdapter, Utils.Observable);
|
||||
Utils.Extend(SelectAdapter, BaseAdapter);
|
||||
|
||||
SelectAdapter.prototype.current = function (callback) {
|
||||
var data = [];
|
||||
|
29
tests/data/base-tests.js
Normal file
29
tests/data/base-tests.js
Normal file
@ -0,0 +1,29 @@
|
||||
module("Data adapters - Base")
|
||||
|
||||
var BaseData = require("select2/data/base");
|
||||
var $ = require("jquery");
|
||||
var Options = require("select2/options");
|
||||
|
||||
var options = new Options({});
|
||||
|
||||
test("current is required", function (assert) {
|
||||
var data = new BaseData($("#qunit-fixture select"), options);
|
||||
|
||||
assert.throws(
|
||||
function () {
|
||||
data.current(function () {});
|
||||
},
|
||||
"current has no default implementation"
|
||||
)
|
||||
});
|
||||
|
||||
test("query is required", function (assert) {
|
||||
var data = new BaseData($("#qunit-fixture select"), options);
|
||||
|
||||
assert.throws(
|
||||
function () {
|
||||
data.query({}, function () {});
|
||||
},
|
||||
"query has no default implementation"
|
||||
);
|
||||
});
|
20
tests/data/base.html
Normal file
20
tests/data/base.html
Normal file
@ -0,0 +1,20 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="../vendor/qunit-1.14.0.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../../dist/css/select2.css" type="text/css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="qunit"></div>
|
||||
<div id="qunit-fixture">
|
||||
<select></select>
|
||||
</div>
|
||||
|
||||
<script src="../vendor/qunit-1.14.0.js" type="text/javascript"></script>
|
||||
<script src="../../vendor/almond-0.2.9.js" type="text/javascript"></script>
|
||||
<script src="../../vendor/jquery-2.1.0.js" type="text/javascript"></script>
|
||||
<script src="../../dist/js/select2.amd.js" type="text/javascript"></script>
|
||||
|
||||
<script src="base-tests.js" type="text/javascript"></script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user