react-dayo
Version:
A Queue component for notification etc
185 lines • 9.28 kB
JavaScript
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
};
import nanoid from 'nanoid';
// import SeedBuilder, {ISeedBuilder, SeedBuilderValues} from '../seed-builder';
import SeedBuilder from '../seed-builder';
import Cycle from '../cycle';
import Interval from '../interval';
var Seed = /** @class */ (function () {
function Seed(BlockComponent, userDefaultValues) {
var _this = this;
if (userDefaultValues === void 0) { userDefaultValues = {}; }
this.id = nanoid();
this.cycle = new Cycle();
this.closed = false;
this.close = function () {
_this.closed = true;
};
this[Symbol.asyncIterator] = function () {
return __asyncGenerator(this, arguments, function () {
var interval;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (this.values === undefined) {
throw new Error('`message` and `timeout` is required');
}
interval = Interval.create();
return [4 /*yield*/, __await(this)];
case 1: return [4 /*yield*/, _a.sent()];
case 2:
_a.sent(); // after enter
return [4 /*yield*/, __await(Promise.race([this.wait(50), this.waitUntilSkipCycle(interval)]).then(this.cycle.proceed))];
case 3:
_a.sent();
return [4 /*yield*/, __await(this)];
case 4: return [4 /*yield*/, _a.sent()];
case 5:
_a.sent(); // after entering
return [4 /*yield*/, __await(Promise.race([this.waitUntilEntered(interval)]))];
case 6:
_a.sent();
return [4 /*yield*/, __await(this)];
case 7: return [4 /*yield*/, _a.sent()];
case 8:
_a.sent(); // after entered
return [4 /*yield*/, __await(Promise.race([
// this.wait(1000), // for debug
// this.wait(500000000), // for debug
this.values.timeout ? this.wait(this.values.timeout) : false,
this.waitUntilClick(interval),
this.waitUntilSkipCycle(interval),
].filter(Boolean)).then(function () {
_this.cycle.proceed();
}))];
case 9:
_a.sent();
return [4 /*yield*/, __await(this)];
case 10: return [4 /*yield*/, _a.sent()];
case 11:
_a.sent(); // after exit
return [4 /*yield*/, __await(Promise.race([this.wait(50)]).then(this.cycle.proceed))];
case 12:
_a.sent();
return [4 /*yield*/, __await(this)];
case 13: return [4 /*yield*/, _a.sent()];
case 14:
_a.sent(); // after exiting
return [4 /*yield*/, __await(Promise.race([this.waitUntilExited(interval)]))];
case 15:
_a.sent();
return [4 /*yield*/, __await(this)];
case 16: return [4 /*yield*/, _a.sent()];
case 17:
_a.sent(); // after exited
return [2 /*return*/];
}
});
});
};
this.BlockComponent = BlockComponent;
this.builder = function () {
var builder = new SeedBuilder(userDefaultValues);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
builder.from(_this);
return builder;
};
}
Seed.prototype.issue = function (values) {
return new Seed(this.BlockComponent, values);
};
Object.defineProperty(Seed.prototype, "theme", {
get: function () {
var transitionTimingFunction = this.values.transitionTimingFunction;
return { transitionTimingFunction: transitionTimingFunction };
},
enumerable: true,
configurable: true
});
Object.defineProperty(Seed.prototype, "message", {
get: function () {
if (this.values === undefined) {
throw new Error('`message` and `timeout` is required');
}
var message = this.values.message;
var name = this.values.name || 'Unknown';
if (message === undefined) {
throw new Error(name + "'s message is undefind");
}
return message;
},
enumerable: true,
configurable: true
});
Seed.prototype.wait = function (msec) {
return new Promise(function (resolve) {
setTimeout(resolve, msec);
});
};
Seed.prototype.waitUntil = function (condition, interval) {
return interval.wait(this, function (onTick) {
return new Promise(function (resolve) {
onTick(function () {
if (condition()) {
resolve();
}
});
});
});
};
Seed.prototype.waitUntilEntered = function (interval) {
return this.waitUntil(this.cycle.isEntered, interval);
};
Seed.prototype.waitUntilExited = function (interval) {
return this.waitUntil(this.cycle.isExited, interval);
};
Seed.prototype.waitUntilClick = function (interval) {
var _this = this;
return this.waitUntil(function () { return _this.closed; }, interval);
};
Seed.prototype.waitUntilSkipCycle = function (interval) {
return this.waitUntil(this.cycle.isSkip, interval);
};
return Seed;
}());
export { Seed };
export default Seed;
//# sourceMappingURL=seed.js.map