From 682817e5d2ceb8fbebf383bd1483085a80b0c4fe Mon Sep 17 00:00:00 2001 From: Brandon Tilley Date: Sun, 18 May 2014 15:43:50 -0700 Subject: [PATCH] Throw when mixing StoreWatchMixin in without calling as a function --- lib/store_watch_mixin.js | 10 +++++++++- test/unit/test_store_watch_mixin.js | 10 ++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/store_watch_mixin.js b/lib/store_watch_mixin.js index aa2c5cd..d25a98a 100644 --- a/lib/store_watch_mixin.js +++ b/lib/store_watch_mixin.js @@ -1,6 +1,6 @@ _ = require("lodash"); -module.exports = function() { +var StoreWatchMixin = function() { var storeNames = Array.prototype.slice.call(arguments); return { componentWillMount: function() { @@ -26,3 +26,11 @@ module.exports = function() { } }; }; + +StoreWatchMixin.componentWillMount = function() { + throw new Error("Fluxbox.StoreWatchMixin is a function that takes one or more " + + "store names as parameters and returns the mixin, e.g.: " + + "mixins[Fluxbox.StoreWatchMixin(\"Store1\", \"Store2\")]"); +}; + +module.exports = StoreWatchMixin; diff --git a/test/unit/test_store_watch_mixin.js b/test/unit/test_store_watch_mixin.js index 05fb857..50146ca 100644 --- a/test/unit/test_store_watch_mixin.js +++ b/test/unit/test_store_watch_mixin.js @@ -95,4 +95,14 @@ describe("FluxMixin", function() { done(); }); }); + + it("throws when attempting to mix in the function directly", function() { + var Comp = React.createClass({ + mixins: [Fluxbox.StoreWatchMixin], + render: function() { return React.DOM.div(); } + }); + expect(function() { + React.renderComponentToString(Comp()); + }).to.throw(/StoreWatchMixin.*function/); + }); });