Skip to content

Commit 473d3f7

Browse files
author
Web Advanced
committed
Added spec to ensure exception would throw when subscribing with anything other then a function. Moving version to 1.0
1 parent 2c98721 commit 473d3f7

File tree

13 files changed

+197
-178
lines changed

13 files changed

+197
-178
lines changed

dev/.nuget/content/Scripts/signals.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ var signals = (function (global, undefined) {
1818
getSignalType,
1919
fire,
2020
unload,
21-
iterator;
21+
iterator,
22+
FUNCTION = 'function';
2223
/**
2324
* Private function that makes the given signal observable.
2425
* <br />- <strong>(signals are an arbitrary string)</strong>
@@ -29,7 +30,7 @@ var signals = (function (global, undefined) {
2930
makeObservable = function (signal) {
3031
var signalType = getSignalType(signal);
3132
if (evts[signalType] === undefined) {
32-
evts[signalType] = [];
33+
evts[signalType] = [];
3334
}
3435
};
3536
/**
@@ -42,6 +43,9 @@ var signals = (function (global, undefined) {
4243
* @param {Object} [context] Context on which listener will be executed (object that should represent the `this`. (default = window)
4344
*/
4445
subscribeToSignal = function (signalName, fn, context) {
46+
if(typeof fn !== FUNCTION) {
47+
throw 'Callback must be a function';
48+
}
4549
var signalType = getSignalType(signalName);
4650
evts[signalType].push({callback: fn, obj: context || global});
4751
};

dev/.nuget/content/Scripts/signals.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/.nuget/signals.js.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package>
33
<metadata>
44
<id>Signals.js</id>
5-
<version>0.1.1</version>
5+
<version>1.0</version>
66
<authors>Web Advanced</authors>
77
<description>Signals.js is a light weight (1k minified) pure JavaScript implementation of the Observer pattern also known as PubSub. Using Signals.js in your JavaScript gives you the ability to break down our applications into smaller, more loosely coupled modules, which can improve general manageability.</description>
88
<summary>Signals.js is a light weight (1k minified) pure JavaScript implementation of the Observer pattern also known as PubSub.</summary>

dev/Signals.js.1.0.nupkg

5.72 KB
Binary file not shown.

dev/signals.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ var signals = (function (global, undefined) {
1818
getSignalType,
1919
fire,
2020
unload,
21-
iterator;
21+
iterator,
22+
FUNCTION = 'function';
2223
/**
2324
* Private function that makes the given signal observable.
2425
* <br />- <strong>(signals are an arbitrary string)</strong>
@@ -29,7 +30,7 @@ var signals = (function (global, undefined) {
2930
makeObservable = function (signal) {
3031
var signalType = getSignalType(signal);
3132
if (evts[signalType] === undefined) {
32-
evts[signalType] = [];
33+
evts[signalType] = [];
3334
}
3435
};
3536
/**
@@ -42,6 +43,9 @@ var signals = (function (global, undefined) {
4243
* @param {Object} [context] Context on which listener will be executed (object that should represent the `this`. (default = window)
4344
*/
4445
subscribeToSignal = function (signalName, fn, context) {
46+
if(typeof fn !== FUNCTION) {
47+
throw 'Callback must be a function';
48+
}
4549
var signalType = getSignalType(signalName);
4650
evts[signalType].push({callback: fn, obj: context || global});
4751
};

dev/specs/signals.specs.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ describe("Signals JS", function () {
2929
expect(signals.isObservable('mock:event')).toEqual(true);
3030
});
3131

32+
it("should throw when adding anything other then a function as the callback", function() {
33+
var failingFunc = function () {
34+
signals.subscribe('mock:event', 'fakeFunc');
35+
};
36+
expect(failingFunc).toThrow('Callback must be a function');
37+
});
38+
3239
it('should be able to set the context of "this" when subscribing', function() {
3340
runs(function() {
3441
var person = new Person('Jon');

docs/files.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ <h2><a href="symbols/src/signals.js.html">signals.js</a></h2>
5757
</div>
5858
<div class="fineprint" style="clear:both;text-align:center">
5959

60-
Documentation generated by <a href="http://code.google.com/p/jsdoc-toolkit/" target="_blankt">JsDoc Toolkit</a> 2.4.0 on Fri Dec 16 2011 14:52:29 GMT-0800 (PST)
60+
Documentation generated by <a href="http://code.google.com/p/jsdoc-toolkit/" target="_blankt">JsDoc Toolkit</a> 2.4.0 on Mon Jan 30 2012 11:18:26 GMT-0800 (PST)
6161
| template based on Steffen Siering <a href="http://github.com/urso/jsdoc-simple">jsdoc-simple</a>.
6262
</div>
6363
</body>

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ <h2><a href="symbols/signals.html">signals</a></h2>
6363
</div>
6464
<div class="fineprint" style="clear:both;text-align:center">
6565

66-
Documentation generated by <a href="http://code.google.com/p/jsdoc-toolkit/" target="_blankt">JsDoc Toolkit</a> 2.4.0 on Fri Dec 16 2011 14:52:29 GMT-0800 (PST)
66+
Documentation generated by <a href="http://code.google.com/p/jsdoc-toolkit/" target="_blankt">JsDoc Toolkit</a> 2.4.0 on Mon Jan 30 2012 11:18:26 GMT-0800 (PST)
6767
| template based on Steffen Siering <a href="http://github.com/urso/jsdoc-simple">jsdoc-simple</a>.
6868
</div>
6969
</body>

docs/symbolindex.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ <h1 id="classTitle">Symbol Index</h1>
207207
</div>
208208
<div class="fineprint" style="clear:both;text-align:center">
209209

210-
Documentation generated by <a href="http://code.google.com/p/jsdoc-toolkit/" target="_blankt">JsDoc Toolkit</a> 2.4.0 on Fri Dec 16 2011 14:52:29 GMT-0800 (PST)
210+
Documentation generated by <a href="http://code.google.com/p/jsdoc-toolkit/" target="_blankt">JsDoc Toolkit</a> 2.4.0 on Mon Jan 30 2012 11:18:26 GMT-0800 (PST)
211211
| template based on Steffen Siering <a href="http://github.com/urso/jsdoc-simple">jsdoc-simple</a>.
212212
</div>
213213
</body>

docs/symbols/_global_.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ <h1 class="classTitle">
484484
<!-- ============================== footer ================================= -->
485485
<div class="fineprint" style="clear:both;text-align:center">
486486

487-
Documentation generated by <a href="http://code.google.com/p/jsdoc-toolkit/" target="_blankt">JsDoc Toolkit</a> 2.4.0 on Fri Dec 16 2011 14:52:29 GMT-0800 (PST)
487+
Documentation generated by <a href="http://code.google.com/p/jsdoc-toolkit/" target="_blankt">JsDoc Toolkit</a> 2.4.0 on Mon Jan 30 2012 11:18:26 GMT-0800 (PST)
488488
| template based on Steffen Siering <a href="http://github.com/urso/jsdoc-simple">jsdoc-simple</a>.
489489
</div>
490490
</body>

0 commit comments

Comments
 (0)