Socket
Socket
Sign inDemoInstall

@dxos/context

Package Overview
Dependencies
Maintainers
13
Versions
2227
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dxos/context - npm Package Compare versions

Comparing version 0.1.2 to 0.1.14

dist/lib/browser/index.mjs

15

package.json
{
"name": "@dxos/context",
"version": "0.1.2",
"version": "0.1.14",
"description": "Async utils.",

@@ -9,4 +9,7 @@ "homepage": "https://dxos.org",

"author": "DXOS.org",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"main": "dist/lib/node/index.cjs",
"browser": {
"./dist/lib/node/index.cjs": "./dist/lib/browser/index.mjs"
},
"types": "dist/types/src/index.d.ts",
"files": [

@@ -17,10 +20,8 @@ "dist",

"dependencies": {
"@dxos/log": "0.1.3"
"@dxos/log": "0.1.14",
"@dxos/util": "0.1.14"
},
"publishConfig": {
"access": "public"
},
"scripts": {
"check": "true"
}
}

@@ -7,6 +7,8 @@ //

import { describe, test } from '@dxos/test';
import { Context } from './context';
describe('Context', function () {
it('dispose calls dispose hooks', function () {
describe('Context', () => {
test('dispose calls dispose hooks', () => {
const ctx = new Context();

@@ -23,7 +25,7 @@

it('dispose waits for async callbacks');
test('dispose waits for async callbacks', () => {});
it('error in dispose callbacks are not propagated');
test('error in dispose callbacks are not propagated', () => {});
it('raised errors are propagated to the error handler', function () {
test('raised errors are propagated to the error handler', () => {
let error!: Error;

@@ -40,10 +42,23 @@ const ctx = new Context({

it('isContext', function () {
test('instanceof', () => {
const ctx = new Context();
expect(Context.isContext(ctx)).toBeTruthy();
expect(ctx instanceof Context).toBeTruthy();
expect(Context.isContext({})).toBeFalsy();
expect({} instanceof Context).toBeFalsy();
expect(Context.isContext(undefined)).toBeFalsy();
expect((undefined as any) instanceof Context).toBeFalsy();
});
test('dispose is idempotent', () => {
const ctx = new Context();
let called = false;
ctx.onDispose(() => {
called = true;
});
void ctx.dispose();
void ctx.dispose();
expect(called).toBeTruthy();
});
});

@@ -6,2 +6,3 @@ //

import { log } from '@dxos/log';
import { safeInstanceof } from '@dxos/util';

@@ -16,16 +17,8 @@ export type ContextErrorHandler = (error: Error) => void;

@safeInstanceof('Context')
export class Context {
// Marker for the isContext method.
private readonly _isContext = true;
/**
* Checks if the object is a context. Not susceptible to prototype duplication that could happen during bundling.
*/
static isContext(value: unknown): value is Context {
return (value as Context)?._isContext === true;
}
private readonly _onError: ContextErrorHandler;
private readonly _disposeCallbacks: DisposeCallback[] = [];
private _isDisposed = false;
private _disposePromise?: Promise<void>;

@@ -43,2 +36,6 @@ constructor({

get disposed() {
return this._isDisposed;
}
/**

@@ -66,4 +63,4 @@ * Schedules a callback to run when the context is disposed.

dispose(): Promise<void> {
if (this._isDisposed) {
throw new Error('Context is already disposed');
if (this._disposePromise) {
return this._disposePromise;
}

@@ -86,3 +83,3 @@ this._isDisposed = true;

return Promise.all(promises).then(() => {});
return (this._disposePromise = Promise.all(promises).then(() => {}));
}

@@ -97,3 +94,3 @@

if (this._isDisposed) {
log.error(`Error in disposed context: ${error}`);
log.warn('Error in disposed context', error);
return;

@@ -100,0 +97,0 @@ }

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