Comparing version 0.4.26 to 0.4.27
@@ -5,6 +5,8 @@ import { FC } from 'react'; | ||
declare type Ensurable<T> = T | void; | ||
declare function action<T = undefined & void>(init?: T): { | ||
declare type Action<T, K = T> = { | ||
(data: T): void; | ||
0: () => Ensurable<T>; | ||
}; | ||
0: () => K; | ||
} & Pick<Promise<T>, 'then' | 'catch' | 'finally'>; | ||
declare function action<T = void>(): Action<T, Ensurable<T>>; | ||
declare function action<T = void>(init: T): Action<T>; | ||
declare function on<T>(target: { | ||
@@ -11,0 +13,0 @@ 0: () => Ensurable<T>; |
@@ -52,3 +52,3 @@ "use strict"; | ||
}; | ||
fn[0] = (() => get()[0]); | ||
fn[0] = () => get()[0]; | ||
promisify(); | ||
@@ -55,0 +55,0 @@ function promisify() { |
{ | ||
"name": "realar", | ||
"version": "0.4.26", | ||
"version": "0.4.27", | ||
"description": "React state manager", | ||
@@ -88,3 +88,3 @@ "repository": { | ||
}, | ||
"gitHead": "f16e1970c65c09ad9928e05813803da47f7b0d0c" | ||
"gitHead": "945d17048e1ee50ec29317ef6a0cc01ca0129855" | ||
} |
@@ -69,13 +69,14 @@ import React, { Context, FC } from 'react'; | ||
type Ensurable<T> = T | void; | ||
type Action<T, K = T> = { | ||
(data: T): void; | ||
0: () => K; | ||
} & Pick<Promise<T>, 'then' | 'catch' | 'finally'>; | ||
function action<T = undefined & void>( | ||
init?: T | ||
): { | ||
(data: T): void; | ||
0: () => Ensurable<T>; | ||
} { | ||
let resolve: (v: T) => void; | ||
function action<T = void>(): Action<T, Ensurable<T>>; | ||
function action<T = void>(init: T): Action<T>; | ||
function action(init?: any) { | ||
let resolve: any; | ||
const [get, set] = box([init]); | ||
const fn = function (data?: T) { | ||
const fn = function (data?: any) { | ||
const ready = resolve; | ||
@@ -87,3 +88,3 @@ promisify(); | ||
fn[0] = (() => get()[0]) as () => Ensurable<T>; | ||
fn[0] = () => get()[0]; | ||
@@ -93,3 +94,3 @@ promisify(); | ||
function promisify() { | ||
const promise = new Promise<T>(r => (resolve = r)); | ||
const promise = new Promise(r => (resolve = r)); | ||
['then', 'catch', 'finally'].forEach(prop => { | ||
@@ -100,3 +101,3 @@ (fn as any)[prop] = (promise as any)[prop].bind(promise); | ||
return fn; | ||
return fn as any; | ||
} | ||
@@ -311,4 +312,4 @@ | ||
target: | ||
| (new (init?: any) => M | (() => M) | { 0: () => M } | [() => M]) | ||
| ((init?: any) => M | (() => M) | { 0: () => M } | [() => M]) | ||
| (new (init?: any) => M | (() => M) | { 0: () => M } | [() => M]) | ||
| ((init?: any) => M | (() => M) | { 0: () => M } | [() => M]) | ||
): M { | ||
@@ -315,0 +316,0 @@ return useValue(shared(target as any)); |
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
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
43603
637