Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@wry/context

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wry/context - npm Package Compare versions

Comparing version 0.7.0 to 0.7.1

lib/bundle.cjs

0

lib/slot.d.ts

@@ -0,0 +0,0 @@ declare const makeSlotClass: () => {

76

lib/slot.js

@@ -1,17 +0,14 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Slot = void 0;
// This currentContext variable will only be used if the makeSlotClass
// function is called, which happens only if this is the first copy of the
// @wry/context package to be imported.
var currentContext = null;
let currentContext = null;
// This unique internal object is used to denote the absence of a value
// for a given Slot, and is never exposed to outside code.
var MISSING_VALUE = {};
var idCounter = 1;
const MISSING_VALUE = {};
let idCounter = 1;
// Although we can't do anything about the cost of duplicated code from
// accidentally bundling multiple copies of the @wry/context package, we can
// avoid creating the Slot class more than once using makeSlotClass.
var makeSlotClass = function () { return /** @class */ (function () {
function Slot() {
const makeSlotClass = () => class Slot {
constructor() {
// If you have a Slot object, you can find out its slot.id, but you cannot

@@ -27,11 +24,11 @@ // guess the slot.id of a Slot you don't have access to, thanks to the

}
Slot.prototype.hasValue = function () {
for (var context_1 = currentContext; context_1; context_1 = context_1.parent) {
hasValue() {
for (let context = currentContext; context; context = context.parent) {
// We use the Slot object iself as a key to its value, which means the
// value cannot be obtained without a reference to the Slot object.
if (this.id in context_1.slots) {
var value = context_1.slots[this.id];
if (this.id in context.slots) {
const value = context.slots[this.id];
if (value === MISSING_VALUE)
break;
if (context_1 !== currentContext) {
if (context !== currentContext) {
// Cache the value in currentContext.slots so the next lookup will

@@ -52,20 +49,18 @@ // be faster. This caching is safe because the tree of contexts and

return false;
};
Slot.prototype.getValue = function () {
}
getValue() {
if (this.hasValue()) {
return currentContext.slots[this.id];
}
};
Slot.prototype.withValue = function (value, callback,
}
withValue(value, callback,
// Given the prevalence of arrow functions, specifying arguments is likely
// to be much more common than specifying `this`, hence this ordering:
args, thisArg) {
var _a;
var slots = (_a = {
__proto__: null
},
_a[this.id] = value,
_a);
var parent = currentContext;
currentContext = { parent: parent, slots: slots };
const slots = {
__proto__: null,
[this.id]: value,
};
const parent = currentContext;
currentContext = { parent, slots };
try {

@@ -79,9 +74,9 @@ // Function.prototype.apply allows the arguments array argument to be

}
};
}
// Capture the current context and wrap a callback function so that it
// reestablishes the captured context when called.
Slot.bind = function (callback) {
var context = currentContext;
static bind(callback) {
const context = currentContext;
return function () {
var saved = currentContext;
const saved = currentContext;
try {

@@ -95,5 +90,5 @@ currentContext = context;

};
};
}
// Immediately run a callback function without any captured context.
Slot.noContext = function (callback,
static noContext(callback,
// Given the prevalence of arrow functions, specifying arguments is likely

@@ -103,3 +98,3 @@ // to be much more common than specifying `this`, hence this ordering:

if (currentContext) {
var saved = currentContext;
const saved = currentContext;
try {

@@ -118,5 +113,4 @@ currentContext = null;

}
};
return Slot;
}()); };
}
};
function maybe(fn) {

@@ -136,11 +130,11 @@ try {

// changes to the Slot class.
var globalKey = "@wry/context:Slot";
var host =
const globalKey = "@wry/context:Slot";
const host =
// Prefer globalThis when available.
// https://github.com/benjamn/wryware/issues/347
maybe(function () { return globalThis; }) ||
maybe(() => globalThis) ||
// Fall back to global, which works in Node.js and may be converted by some
// bundlers to the appropriate identifier (window, self, ...) depending on the
// bundling target. https://github.com/endojs/endo/issues/576#issuecomment-1178515224
maybe(function () { return global; }) ||
maybe(() => global) ||
// Otherwise, use a dummy host that's local to this module. We used to fall

@@ -152,4 +146,4 @@ // back to using the Array constructor as a namespace, but that was flagged in

// globalKey property.
var globalHost = host;
exports.Slot = globalHost[globalKey] ||
const globalHost = host;
export const Slot = globalHost[globalKey] ||
// Earlier versions of this package stored the globalKey property on the Array

@@ -156,0 +150,0 @@ // constructor, so we check there as well, to prevent Slot class duplication.

{
"name": "@wry/context",
"version": "0.7.0",
"version": "0.7.1",
"author": "Ben Newman <ben@eloper.dev>",
"description": "Manage contextual information needed by (a)synchronous tasks without explicitly passing objects around",
"license": "MIT",
"main": "lib/context.js",
"module": "lib/context.esm.js",
"types": "lib/context.d.ts",
"type": "module",
"main": "lib/bundle.cjs",
"module": "lib/index.js",
"types": "lib/index.d.ts",
"keywords": [],

@@ -20,9 +21,13 @@ "homepage": "https://github.com/benjamn/wryware",

"scripts": {
"clean": "../../node_modules/.bin/rimraf lib",
"tsc": "../../node_modules/.bin/tsc",
"rollup": "../../node_modules/.bin/rollup -c",
"build": "npm run clean && npm run tsc && npm run rollup",
"mocha": "../../scripts/test.sh lib/tests.js",
"build": "npm run clean:before && npm run tsc && npm run rollup && npm run clean:after",
"clean:before": "rimraf lib",
"tsc": "npm run tsc:es5 && npm run tsc:esm",
"tsc:es5": "tsc -p tsconfig.es5.json",
"tsc:esm": "tsc -p tsconfig.json",
"rollup": "rollup -c rollup.config.js",
"clean:after": "rimraf lib/es5",
"prepare": "npm run build",
"test": "npm run build && npm run mocha"
"test:cjs": "../../scripts/test.sh lib/tests/bundle.cjs",
"test:esm": "../../scripts/test.sh lib/tests/bundle.js",
"test": "npm run test:esm && npm run test:cjs"
},

@@ -35,3 +40,3 @@ "dependencies": {

},
"gitHead": "4cb5c26fead3594a6b17cf9d67968cfa8d11e045"
"gitHead": "85851ce64233c9fe7cc4dba987cf26ffb12dcecf"
}

@@ -1,40 +0,1 @@

import typescriptPlugin from 'rollup-plugin-typescript2';
import typescript from 'typescript';
const globals = {
__proto__: null,
tslib: "tslib",
};
function external(id) {
return id in globals;
}
export default [{
input: "src/context.ts",
external,
output: {
file: "lib/context.esm.js",
format: "esm",
sourcemap: true,
globals,
},
plugins: [
typescriptPlugin({
typescript,
tsconfig: "./tsconfig.rollup.json",
}),
],
}, {
input: "lib/context.esm.js",
external,
output: {
// Intentionally overwrite the context.js file written by tsc:
file: "lib/context.js",
format: "cjs",
exports: "named",
sourcemap: true,
name: "context",
globals,
},
}];
export { default } from "../../scripts/rollup.config.js";

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc