@dxos/context
Advanced tools
Comparing version 0.1.2 to 0.1.14
{ | ||
"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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
26706
405
2
2
+ Added@dxos/util@0.1.14
+ Added@dxos/debug@0.1.14(transitive)
+ Added@dxos/keys@0.1.14(transitive)
+ Added@dxos/log@0.1.14(transitive)
+ Added@dxos/node-std@0.1.14(transitive)
+ Added@dxos/util@0.1.14(transitive)
+ Addedassert@2.1.0(transitive)
+ Addeddebug@4.3.7(transitive)
+ Addeddefine-properties@1.2.1(transitive)
+ Addedevents@3.3.0(transitive)
+ Addedis-nan@1.3.2(transitive)
+ Addedms@2.1.3(transitive)
+ Addedobject-is@1.1.6(transitive)
+ Addedobject-keys@1.1.1(transitive)
+ Addedobject.assign@4.1.5(transitive)
+ Addedpath-browserify@1.0.1(transitive)
+ Addedrandombytes@2.1.0(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
- Removed@dxos/log@0.1.3(transitive)
Updated@dxos/log@0.1.14