Launch Week Day 4: Introducing Data Exports.Learn More
Socket
Book a DemoSign in
Socket

unctx

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unctx - npm Package Compare versions

Comparing version
1.0.1
to
1.0.2
+47
CHANGELOG.md
# Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
### [1.0.2](https://github.com/unjs/unctx/compare/v1.0.1...v1.0.2) (2021-08-24)
### Bug Fixes
* **call:** don't set instance to null when using singleton ([248dc32](https://github.com/unjs/unctx/commit/248dc3218e70238a6091cf5707bafbeb2d1fd91f)), closes [nuxt/framework#51](https://github.com/nuxt/framework/issues/51)
### [1.0.1](https://github.com/unjs/unctx/compare/v1.0.0...v1.0.1) (2021-06-24)
## [1.0.0](https://github.com/unjs/unctx/compare/v0.0.4...v1.0.0) (2021-06-24)
### [0.0.4](https://github.com/unjs/unctx/compare/v0.0.3...v0.0.4) (2021-06-24)
### Features
* singleton pattern support ([f506172](https://github.com/unjs/unctx/commit/f5061726e89771605ba8f7663ec89e3f0c914033))
### Bug Fixes
* unset context if callback throws immediate error ([f045049](https://github.com/unjs/unctx/commit/f04504953630edf840e7389f0838b63674ac2f34))
### [0.0.3](https://github.com/unjs/unctx/compare/v0.0.2...v0.0.3) (2021-03-30)
### Bug Fixes
* add missing return to createNamespace ([04886ef](https://github.com/unjs/unctx/commit/04886efb014f2715de924b936fd7b6b210454531))
### [0.0.2](https://github.com/unjs/unctx/compare/v0.0.1...v0.0.2) (2021-03-30)
### Features
* simplify useContext ([4a740bc](https://github.com/unjs/unctx/commit/4a740bc9c7c6013569859018ef5d622acbb6b55a))
### 0.0.1 (2021-03-30)
### Features
* initial commit ([80fe123](https://github.com/unjs/unctx/commit/80fe123c7ba597ca827be830fc7f021ad28d94da))
+9
-2

@@ -7,2 +7,3 @@ 'use strict';

let currentInstance = null;
let isSingleton = false;
const checkConflict = (instance) => {

@@ -20,5 +21,7 @@ if (currentInstance && currentInstance !== instance) {

currentInstance = instance;
isSingleton = true;
},
unset: () => {
currentInstance = null;
isSingleton = false;
},

@@ -30,6 +33,10 @@ call: (instance, cb) => {

const res = cb();
currentInstance = null;
if (!isSingleton) {
currentInstance = null;
}
return res;
} catch (err) {
currentInstance = null;
if (!isSingleton) {
currentInstance = null;
}
throw err;

@@ -36,0 +43,0 @@ }

function createContext() {
let currentInstance = null;
let isSingleton = false;
const checkConflict = (instance) => {

@@ -15,5 +16,7 @@ if (currentInstance && currentInstance !== instance) {

currentInstance = instance;
isSingleton = true;
},
unset: () => {
currentInstance = null;
isSingleton = false;
},

@@ -25,6 +28,10 @@ call: (instance, cb) => {

const res = cb();
currentInstance = null;
if (!isSingleton) {
currentInstance = null;
}
return res;
} catch (err) {
currentInstance = null;
if (!isSingleton) {
currentInstance = null;
}
throw err;

@@ -31,0 +38,0 @@ }

+1
-1
{
"name": "unctx",
"version": "1.0.1",
"version": "1.0.2",
"description": "Composition-api in Vanilla js",

@@ -5,0 +5,0 @@ "repository": "unjs/unctx",