1 | "use strict";
|
2 |
|
3 | require("core-js/modules/es.symbol.js");
|
4 |
|
5 | require("core-js/modules/es.symbol.description.js");
|
6 |
|
7 | require("core-js/modules/es.symbol.iterator.js");
|
8 |
|
9 | require("core-js/modules/es.array.slice.js");
|
10 |
|
11 | require("core-js/modules/es.function.name.js");
|
12 |
|
13 | require("core-js/modules/es.array.from.js");
|
14 |
|
15 | Object.defineProperty(exports, "__esModule", {
|
16 | value: true
|
17 | });
|
18 | exports.useStory = useStory;
|
19 | exports.useStories = useStories;
|
20 |
|
21 | require("regenerator-runtime/runtime.js");
|
22 |
|
23 | require("core-js/modules/es.promise.js");
|
24 |
|
25 | require("core-js/modules/es.object.to-string.js");
|
26 |
|
27 | require("core-js/modules/es.string.iterator.js");
|
28 |
|
29 | require("core-js/modules/es.array.iterator.js");
|
30 |
|
31 | require("core-js/modules/web.dom-collections.iterator.js");
|
32 |
|
33 | require("core-js/modules/es.array.map.js");
|
34 |
|
35 | require("core-js/modules/es.object.assign.js");
|
36 |
|
37 | var _react = require("react");
|
38 |
|
39 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
40 |
|
41 | function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
42 |
|
43 | function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
44 |
|
45 | function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
46 |
|
47 | function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
48 |
|
49 | function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
50 |
|
51 | function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
52 |
|
53 | function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
54 |
|
55 | function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
56 |
|
57 | function useStory(storyId, context) {
|
58 | var stories = useStories([storyId], context);
|
59 | return stories && stories[0];
|
60 | }
|
61 |
|
62 | function useStories(storyIds, context) {
|
63 | var initialStoriesById = context.componentStories().reduce(function (acc, story) {
|
64 | acc[story.id] = story;
|
65 | return acc;
|
66 | }, {});
|
67 |
|
68 | var _useState = (0, _react.useState)(initialStoriesById),
|
69 | _useState2 = _slicedToArray(_useState, 2),
|
70 | storiesById = _useState2[0],
|
71 | setStories = _useState2[1];
|
72 |
|
73 | (0, _react.useEffect)(function () {
|
74 | Promise.all(storyIds.map( function () {
|
75 | var _ref = _asyncToGenerator( regeneratorRuntime.mark(function _callee(storyId) {
|
76 | var story;
|
77 | return regeneratorRuntime.wrap(function _callee$(_context) {
|
78 | while (1) {
|
79 | switch (_context.prev = _context.next) {
|
80 | case 0:
|
81 | _context.next = 2;
|
82 | return context.loadStory(storyId);
|
83 |
|
84 | case 2:
|
85 | story = _context.sent;
|
86 | setStories(function (current) {
|
87 | return current[storyId] === story ? current : Object.assign({}, current, _defineProperty({}, storyId, story));
|
88 | });
|
89 |
|
90 | case 4:
|
91 | case "end":
|
92 | return _context.stop();
|
93 | }
|
94 | }
|
95 | }, _callee);
|
96 | }));
|
97 |
|
98 | return function (_x) {
|
99 | return _ref.apply(this, arguments);
|
100 | };
|
101 | }()));
|
102 | });
|
103 | return storyIds.map(function (storyId) {
|
104 | return storiesById[storyId];
|
105 | });
|
106 | } |
\ | No newline at end of file |