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

optimism

Package Overview
Dependencies
Maintainers
1
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

optimism - npm Package Compare versions

Comparing version 0.9.0 to 0.9.1

86

lib/bundle.esm.js

@@ -0,1 +1,4 @@

import { Slot } from '@wry/context';
export { bind as bindContext, noContext, setTimeout, asyncFromGen } from '@wry/context';
function defaultDispose() { }

@@ -87,72 +90,3 @@ var Cache = /** @class */ (function () {

var currentContext = null;
function getParentEntry() {
return currentContext && currentContext.entry;
}
function withEntry(callback, entry) {
var parent = currentContext;
currentContext = { parent: parent, entry: entry };
try {
return callback();
}
finally {
currentContext = parent;
}
}
// Immediately run a callback function without any captured context.
function noContext(callback) {
return withEntry(callback, null);
}
// Capture the current context and wrap a callback function so that it
// reestablishes the captured context when called.
function bindContext(callback) {
var context = currentContext;
return function () {
var saved = currentContext;
try {
currentContext = context;
return callback.apply(this, arguments);
}
finally {
currentContext = saved;
}
};
}
function setTimeoutWithContext(callback, delay) {
return setTimeout(bindContext(callback), delay);
}
function isPromiseLike(value) {
return value && typeof value.then === "function";
}
// Turn any generator function into an async function (using yield instead
// of await), with context automatically preserved across yields.
function asyncFromGen(genFn) {
return function () {
var context = currentContext;
var gen = genFn.apply(this, arguments);
return new Promise(function (resolve, reject) {
function pump(valueToSend) {
var saved = currentContext;
var result;
try {
currentContext = context;
result = gen.next(valueToSend);
currentContext = saved;
}
catch (error) {
currentContext = saved;
return reject(error);
}
var next = result.done ? resolve : pump;
if (isPromiseLike(result.value)) {
result.value.then(next, reject);
}
else {
next(result.value);
}
}
pump();
});
};
}
var parentEntrySlot = new Slot();

@@ -229,3 +163,3 @@ var UNKNOWN_VALUE = Object.create(null);

function rememberParent(child) {
var parent = getParentEntry();
var parent = parentEntrySlot.getValue();
if (parent) {

@@ -287,5 +221,5 @@ child.parents.add(parent);

try {
withEntry(function () {
parentEntrySlot.withValue(entry, function () {
entry.value = entry.fn.apply(null, entry.args);
}, entry);
});
threw = false;

@@ -501,3 +435,3 @@ }

function optimistic() {
if (disposable && !getParentEntry()) {
if (disposable && !parentEntrySlot.hasValue()) {
// If there's no current parent computation, and this wrapped

@@ -534,3 +468,3 @@ // function is disposable (meaning we don't care about entry.value,

// computation that might be flummoxed by the cleaning.
if (!getParentEntry()) {
if (!parentEntrySlot.hasValue()) {
cache.clean();

@@ -553,3 +487,3 @@ }

export { defaultMakeCacheKey, KeyTrie, wrap, bindContext, noContext, setTimeoutWithContext as setTimeout, asyncFromGen };
export { defaultMakeCacheKey, KeyTrie, wrap };
//# sourceMappingURL=bundle.esm.js.map

12

lib/context.d.ts

@@ -1,9 +0,3 @@

/// <reference types="node" />
import { AnyEntry } from './entry';
export declare function getParentEntry(): import("./entry").Entry<any, any> | null;
export declare function withEntry<TResult>(callback: () => TResult, entry: AnyEntry | null): TResult;
export declare function noContext<TResult>(callback: () => TResult): TResult;
export declare function bindContext<TArgs extends any[], TResult>(callback: (...args: TArgs) => TResult): (...args: TArgs) => TResult;
export { setTimeoutWithContext as setTimeout };
declare function setTimeoutWithContext(callback: () => any, delay: number): NodeJS.Timeout;
export declare function asyncFromGen<TArgs extends any[], TResult>(genFn: (...args: TArgs) => IterableIterator<TResult>): (...args: TArgs) => Promise<TResult>;
import { Slot } from "@wry/context";
export declare const parentEntrySlot: Slot<import("./entry").Entry<any, any>>;
export { bind as bindContext, noContext, setTimeout, asyncFromGen, } from "@wry/context";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var currentContext = null;
function getParentEntry() {
return currentContext && currentContext.entry;
}
exports.getParentEntry = getParentEntry;
function withEntry(callback, entry) {
var parent = currentContext;
currentContext = { parent: parent, entry: entry };
try {
return callback();
}
finally {
currentContext = parent;
}
}
exports.withEntry = withEntry;
// Immediately run a callback function without any captured context.
function noContext(callback) {
return withEntry(callback, null);
}
exports.noContext = noContext;
// Capture the current context and wrap a callback function so that it
// reestablishes the captured context when called.
function bindContext(callback) {
var context = currentContext;
return function () {
var saved = currentContext;
try {
currentContext = context;
return callback.apply(this, arguments);
}
finally {
currentContext = saved;
}
};
}
exports.bindContext = bindContext;
function setTimeoutWithContext(callback, delay) {
return setTimeout(bindContext(callback), delay);
}
exports.setTimeout = setTimeoutWithContext;
function isPromiseLike(value) {
return value && typeof value.then === "function";
}
// Turn any generator function into an async function (using yield instead
// of await), with context automatically preserved across yields.
function asyncFromGen(genFn) {
return function () {
var context = currentContext;
var gen = genFn.apply(this, arguments);
return new Promise(function (resolve, reject) {
function pump(valueToSend) {
var saved = currentContext;
var result;
try {
currentContext = context;
result = gen.next(valueToSend);
currentContext = saved;
}
catch (error) {
currentContext = saved;
return reject(error);
}
var next = result.done ? resolve : pump;
if (isPromiseLike(result.value)) {
result.value.then(next, reject);
}
else {
next(result.value);
}
}
pump();
});
};
}
exports.asyncFromGen = asyncFromGen;
var context_1 = require("@wry/context");
exports.parentEntrySlot = new context_1.Slot();
var context_2 = require("@wry/context");
exports.bindContext = context_2.bind;
exports.noContext = context_2.noContext;
exports.setTimeout = context_2.setTimeout;
exports.asyncFromGen = context_2.asyncFromGen;
//# sourceMappingURL=context.js.map

@@ -75,3 +75,3 @@ "use strict";

function rememberParent(child) {
var parent = context_1.getParentEntry();
var parent = context_1.parentEntrySlot.getValue();
if (parent) {

@@ -133,5 +133,5 @@ child.parents.add(parent);

try {
context_1.withEntry(function () {
context_1.parentEntrySlot.withValue(entry, function () {
entry.value = entry.fn.apply(null, entry.args);
}, entry);
});
threw = false;

@@ -138,0 +138,0 @@ }

@@ -41,3 +41,3 @@ "use strict";

function optimistic() {
if (disposable && !context_1.getParentEntry()) {
if (disposable && !context_1.parentEntrySlot.hasValue()) {
// If there's no current parent computation, and this wrapped

@@ -74,3 +74,3 @@ // function is disposable (meaning we don't care about entry.value,

// computation that might be flummoxed by the cleaning.
if (!context_1.getParentEntry()) {
if (!context_1.parentEntrySlot.hasValue()) {
cache.clean();

@@ -77,0 +77,0 @@ }

{
"name": "optimism",
"version": "0.9.0",
"version": "0.9.1",
"author": "Ben Newman <ben@benjamn.com>",

@@ -38,3 +38,3 @@ "description": "Composable reactive caching with efficient invalidation.",

"@types/mocha": "^5.2.6",
"@types/node": "^10.14.1",
"@types/node": "^11.13.0",
"fibers": "^3.0.0",

@@ -46,3 +46,6 @@ "mocha": "^5.0.0",

"typescript": "^3.3.3333"
},
"dependencies": {
"@wry/context": "^0.2.1"
}
}

@@ -1,5 +0,3 @@

# optimism [![Build Status](https://travis-ci.org/benjamn/optimism.svg?branch=master)](https://travis-ci.org/benjamn/optimism)
# optimism &nbsp; [![Build Status](https://travis-ci.org/benjamn/optimism.svg?branch=master)](https://travis-ci.org/benjamn/optimism) [![Greenkeeper badge](https://badges.greenkeeper.io/benjamn/optimism.svg)](https://greenkeeper.io/)
[![Greenkeeper badge](https://badges.greenkeeper.io/benjamn/optimism.svg)](https://greenkeeper.io/)
Composable reactive caching with efficient invalidation.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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