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

async-ref

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-ref - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

6

dist/index.d.ts

@@ -13,4 +13,6 @@ declare type Notify = () => void;

then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
resolve(value: T): void;
reject(error: Error): void;
resolve(value: T): AsyncMutableRefObject<T>;
reject(error: Error): AsyncMutableRefObject<T>;
freeze(): this;
isFrozen(): boolean;
}

@@ -17,0 +19,0 @@ declare const createAsyncRef: <T>(notify?: Notify) => AsyncMutableRefObject<T>;

@@ -45,3 +45,3 @@ var __defProp = Object.defineProperty;

// src/async-ref.ts
var _promise, _notify, _state, _resolve, _reject;
var _promise, _notify, _frozen, _state, _resolve, _reject;
var AsyncMutableRefObject = class {

@@ -52,2 +52,3 @@ constructor(notify = () => {

__privateAdd(this, _notify, void 0);
__privateAdd(this, _frozen, false);
__privateAdd(this, _state, {

@@ -105,9 +106,23 @@ status: 0 /* Loading */,

__privateGet(this, _resolve).call(this, value);
return this;
}
reject(error) {
__privateGet(this, _reject).call(this, error);
return this;
}
freeze() {
__privateSet(this, _frozen, true);
__privateSet(this, _resolve, () => {
});
__privateSet(this, _reject, () => {
});
return this;
}
isFrozen() {
return __privateGet(this, _frozen);
}
};
_promise = new WeakMap();
_notify = new WeakMap();
_frozen = new WeakMap();
_state = new WeakMap();

@@ -114,0 +129,0 @@ _resolve = new WeakMap();

{
"name": "async-ref",
"description": "Async ref objects for React. A tiny bridge between React.useSyncExternalStore and React.Suspense.",
"version": "0.1.3",
"version": "0.1.4",
"main": "dist/index.js",

@@ -6,0 +6,0 @@ "module": "dist/index.mjs",

@@ -154,2 +154,15 @@ # A tiny bridge between React.useSyncExternalStore and React Suspense

If you want to prevent the ref from changing its state, you can freeze it.
```ts
const ref = createAsyncRef<number>(listener);
ref.current = 12;
ref.freeze();
ref.current = 400;
expect(ref.current).toEqual(12);
```
## Safely getting the value without Suspense

@@ -156,0 +169,0 @@

@@ -23,3 +23,3 @@ type Notify = () => void;

#notify: Notify;
#frozen = false;
#state: RefState<T> = {

@@ -103,9 +103,25 @@ status: Status.Loading,

public resolve(value: T): void {
public resolve(value: T): AsyncMutableRefObject<T> {
this.#resolve(value);
return this;
}
public reject(error: Error): void {
public reject(error: Error): AsyncMutableRefObject<T> {
this.#reject(error);
return this;
}
public freeze() {
this.#frozen = true;
this.#resolve = () => {};
this.#reject = () => {};
return this;
}
public isFrozen() {
return this.#frozen;
}
}

@@ -112,0 +128,0 @@

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