@wry/context
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -5,3 +5,3 @@ /// <reference types="node" /> | ||
hasValue(): boolean; | ||
getValue: () => TValue | undefined; | ||
getValue(): TValue | undefined; | ||
withValue<TResult, TArgs extends any[], TThis = any>(value: TValue, callback: (this: TThis, ...args: TArgs) => TResult, args?: TArgs, thisArg?: TThis): TResult; | ||
@@ -8,0 +8,0 @@ } |
@@ -6,17 +6,13 @@ var currentContext = null; | ||
var idCounter = 1; | ||
function makeUniqueId() { | ||
return ["slot", idCounter++, Date.now(), Math.random().toString(36).slice(2)].join(":"); | ||
} | ||
var Slot = /** @class */ (function () { | ||
function Slot() { | ||
var _this = this; | ||
// If you have a Slot object, you can find out its slot.id by circumventing | ||
// TypeScript's privacy restrictions, but you can't guess the slot.id of a | ||
// Slot you don't have access to, thanks to the randomized suffix. | ||
this.id = makeUniqueId(); | ||
this.getValue = function () { | ||
if (_this.hasValue()) { | ||
return currentContext.slots[_this.id]; | ||
} | ||
}; | ||
this.id = [ | ||
"slot", | ||
idCounter++, | ||
Date.now(), | ||
Math.random().toString(36).slice(2), | ||
].join(":"); | ||
} | ||
@@ -49,2 +45,7 @@ Slot.prototype.hasValue = function () { | ||
}; | ||
Slot.prototype.getValue = function () { | ||
if (this.hasValue()) { | ||
return currentContext.slots[this.id]; | ||
} | ||
}; | ||
Slot.prototype.withValue = function (value, callback, | ||
@@ -51,0 +52,0 @@ // Given the prevalence of arrow functions, specifying arguments is likely |
@@ -10,17 +10,13 @@ 'use strict'; | ||
var idCounter = 1; | ||
function makeUniqueId() { | ||
return ["slot", idCounter++, Date.now(), Math.random().toString(36).slice(2)].join(":"); | ||
} | ||
var Slot = /** @class */ (function () { | ||
function Slot() { | ||
var _this = this; | ||
// If you have a Slot object, you can find out its slot.id by circumventing | ||
// TypeScript's privacy restrictions, but you can't guess the slot.id of a | ||
// Slot you don't have access to, thanks to the randomized suffix. | ||
this.id = makeUniqueId(); | ||
this.getValue = function () { | ||
if (_this.hasValue()) { | ||
return currentContext.slots[_this.id]; | ||
} | ||
}; | ||
this.id = [ | ||
"slot", | ||
idCounter++, | ||
Date.now(), | ||
Math.random().toString(36).slice(2), | ||
].join(":"); | ||
} | ||
@@ -53,2 +49,7 @@ Slot.prototype.hasValue = function () { | ||
}; | ||
Slot.prototype.getValue = function () { | ||
if (this.hasValue()) { | ||
return currentContext.slots[this.id]; | ||
} | ||
}; | ||
Slot.prototype.withValue = function (value, callback, | ||
@@ -55,0 +56,0 @@ // Given the prevalence of arrow functions, specifying arguments is likely |
{ | ||
"name": "@wry/context", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"author": "Ben Newman <ben@eloper.dev>", | ||
@@ -31,3 +31,3 @@ "description": "Manage contextual information needed by (a)synchronous tasks without explicitly passing objects around", | ||
}, | ||
"gitHead": "ac45fec8d46eedc1518265d9141266d352278fb1" | ||
"gitHead": "df6235c13199ae5e212e58853126915a9ebf59c1" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
348
18172