UNPKG

1.79 kBJavaScriptView Raw
1import "core-js/modules/es.function.name.js";
2import "core-js/modules/es.array.concat.js";
3export var makeDecorator = function makeDecorator(_ref) {
4 var name = _ref.name,
5 parameterName = _ref.parameterName,
6 wrapper = _ref.wrapper,
7 _ref$skipIfNoParamete = _ref.skipIfNoParametersOrOptions,
8 skipIfNoParametersOrOptions = _ref$skipIfNoParamete === void 0 ? false : _ref$skipIfNoParamete;
9
10 var decorator = function decorator(options) {
11 return function (storyFn, context) {
12 var parameters = context.parameters && context.parameters[parameterName];
13
14 if (parameters && parameters.disable) {
15 return storyFn(context);
16 }
17
18 if (skipIfNoParametersOrOptions && !options && !parameters) {
19 return storyFn(context);
20 }
21
22 return wrapper(storyFn, context, {
23 options: options,
24 parameters: parameters
25 });
26 };
27 };
28
29 return function () {
30 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
31 args[_key] = arguments[_key];
32 }
33
34 // Used without options as .addDecorator(decorator)
35 if (typeof args[0] === 'function') {
36 return decorator().apply(void 0, args);
37 }
38
39 return function () {
40 // Used as [.]addDecorator(decorator(options))
41 if (arguments.length > 1) {
42 // Used as [.]addDecorator(decorator(option1, option2))
43 if (args.length > 1) {
44 return decorator(args).apply(void 0, arguments);
45 }
46
47 return decorator.apply(void 0, args).apply(void 0, arguments);
48 }
49
50 throw new Error("Passing stories directly into ".concat(name, "() is not allowed,\n instead use addDecorator(").concat(name, ") and pass options with the '").concat(parameterName, "' parameter"));
51 };
52 };
53};
\No newline at end of file