Commit bbde5a57 authored by Rafael Ostertag's avatar Rafael Ostertag
Browse files

Dropped FunctionList.js

parent 0d559902
/**
* @author Rafael Ostertag <rafael.ostertag@math.uzh.ch>
*/
/* global $ */
var QfqNS = QfqNS || {};
QfqNS.Helper = QfqNS.Helper || {};
(function (n) {
'use strict';
/**
* @deprecated
* @constructor
*/
n.FunctionList = function () {
this.functions = [];
};
n.FunctionList.prototype.addFunction = function (func, thisObj) {
if (typeof func !== "function") {
throw new TypeError("Expected function");
}
if (thisObj) {
this.functions.push([func, thisObj]);
} else {
this.functions.push(func);
}
};
n.FunctionList.prototype.call = function () {
var _arguments = arguments;
this.functions.forEach(function (func) {
if (typeof func === "function") {
func.apply(undefined, _arguments);
} else {
// func is an array [ Function, thisObj ]
func[0].apply(func[1], _arguments);
}
});
};
})(QfqNS.Helper);
\ No newline at end of file
......@@ -22,7 +22,6 @@
<script src="../../js/qfq.debug.js"></script>
<!-- include spec files here... -->
<script src="spec/HelperFunctionListSpec.js"></script>
<script src="spec/ElementFormGroupSpec.js"></script>
<script src="spec/ElementTextualSpec.js"></script>
<script src="spec/ElementRadioSpec.js"></script>
......
/**
* @author Rafael Ostertag <rafael.ostertag@math.uzh.ch>
*/
/* global describe */
/* global it */
/* global expect */
/* global QfqNS */
/* global beforeAll */
/* global beforeEach */
/* global jasmine */
describe("Helper FunctionList", function () {
'use strict';
var functionList;
beforeEach(function () {
functionList = new QfqNS.Helper.FunctionList();
});
it("should call one function properly", function () {
var spy = jasmine.createSpy('SingleFunction');
functionList.addFunction(spy);
functionList.call("1", 2, {});
expect(spy).toHaveBeenCalled();
expect(spy).toHaveBeenCalledWith("1", 2, {});
});
it("should call several functions properly", function () {
var spy1 = jasmine.createSpy('Function1');
var spy2 = jasmine.createSpy('Function2');
var spy3 = jasmine.createSpy('Function3');
functionList.addFunction(spy1);
functionList.addFunction(spy2);
functionList.addFunction(spy3);
functionList.call("1", 2, {});
expect(spy1).toHaveBeenCalled();
expect(spy1).toHaveBeenCalledWith("1", 2, {});
expect(spy2).toHaveBeenCalled();
expect(spy2).toHaveBeenCalledWith("1", 2, {});
expect(spy3).toHaveBeenCalled();
expect(spy3).toHaveBeenCalledWith("1", 2, {});
});
it("should pass proper object as `this'", function () {
var obj = {
val: 0,
f: function (a) {
this.val = a;
}
};
var spy1 = jasmine.createSpy('Function1');
functionList.addFunction(obj.f, obj);
functionList.addFunction(spy1);
functionList.call(2);
expect(spy1).toHaveBeenCalledWith(2);
expect(obj.val).toBe(2);
});
it("should not allow adding anything besides FunctionS", function () {
expect(function () {
functionList.add('bla');
}).toThrowError(TypeError);
});
}
);
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment