@hookstate/core
Advanced tools
Comparing version 0.10.0 to 0.10.1
@@ -164,5 +164,8 @@ import React from 'react'; | ||
}()); | ||
var SynteticID = Symbol('SynteticTypeInferenceMarker'); | ||
var StateRefImpl = /** @class */ (function () { | ||
function StateRefImpl(state) { | ||
this.state = state; | ||
// tslint:disable-next-line: variable-name | ||
this.__synteticTypeInferenceMarkerRef = SynteticID; | ||
} | ||
@@ -180,2 +183,11 @@ StateRefImpl.prototype.with = function (plugin) { | ||
}()); | ||
var StateInfImpl = /** @class */ (function () { | ||
function StateInfImpl(wrapped, transform) { | ||
this.wrapped = wrapped; | ||
this.transform = transform; | ||
// tslint:disable-next-line: variable-name | ||
this.__synteticTypeInferenceMarkerInf = SynteticID; | ||
} | ||
return StateInfImpl; | ||
}()); | ||
var StateLinkImpl = /** @class */ (function () { | ||
@@ -518,3 +530,3 @@ function StateLinkImpl(state, path, onUpdateUsed, valueUntracked) { | ||
} | ||
function useDerivedStateLink(originLink) { | ||
function useScopedStateLink(originLink) { | ||
var _a = React.useState({}), setValue = _a[1]; | ||
@@ -524,3 +536,2 @@ return useSubscribedStateLink(originLink.state, originLink.path, function () { | ||
}, originLink, originLink.disabledTracking); | ||
// note PrerenderTransform strategy is not inherited intentionally | ||
} | ||
@@ -530,3 +541,3 @@ function useAutoStateLink(initialState) { | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
return useDerivedStateLink(initialState); | ||
return useScopedStateLink(initialState); | ||
} | ||
@@ -570,10 +581,17 @@ if (initialState instanceof StateRefImpl) { | ||
} | ||
/// | ||
/// EXPORTED IMPLEMENTATIONS | ||
/// | ||
function createStateLink(initial) { | ||
return new StateRefImpl(createState(initial)); | ||
function createStateLink(initial, transform) { | ||
var ref = new StateRefImpl(createState(initial)); | ||
if (transform) { | ||
return new StateInfImpl(ref, transform); | ||
} | ||
return ref; | ||
} | ||
function useStateLink(initialState, transform) { | ||
var link = useAutoStateLink(initialState); | ||
function useStateLink(source, transform) { | ||
var state = source instanceof StateInfImpl | ||
? source.wrapped | ||
: source; | ||
var link = useAutoStateLink(state); | ||
if (source instanceof StateInfImpl) { | ||
return injectTransform(link, source.transform); | ||
} | ||
if (transform) { | ||
@@ -584,4 +602,6 @@ return injectTransform(link, transform); | ||
} | ||
function useStateLinkUnmounted(state, transform) { | ||
var stateRef = state; | ||
function useStateLinkUnmounted(source, transform) { | ||
var stateRef = source instanceof StateInfImpl | ||
? source.wrapped | ||
: source; | ||
var link = new StateLinkImpl(stateRef.state, RootPath, | ||
@@ -592,2 +612,5 @@ // it is assumed the client discards the state link once it is used | ||
}, stateRef.state.get(RootPath)).with(DisabledTracking); // it does not matter how it is used, it is not subscribed anyway | ||
if (source instanceof StateInfImpl) { | ||
return source.transform(link, undefined); | ||
} | ||
if (transform) { | ||
@@ -594,0 +617,0 @@ return transform(link); |
@@ -170,5 +170,8 @@ 'use strict'; | ||
}()); | ||
var SynteticID = Symbol('SynteticTypeInferenceMarker'); | ||
var StateRefImpl = /** @class */ (function () { | ||
function StateRefImpl(state) { | ||
this.state = state; | ||
// tslint:disable-next-line: variable-name | ||
this.__synteticTypeInferenceMarkerRef = SynteticID; | ||
} | ||
@@ -186,2 +189,11 @@ StateRefImpl.prototype.with = function (plugin) { | ||
}()); | ||
var StateInfImpl = /** @class */ (function () { | ||
function StateInfImpl(wrapped, transform) { | ||
this.wrapped = wrapped; | ||
this.transform = transform; | ||
// tslint:disable-next-line: variable-name | ||
this.__synteticTypeInferenceMarkerInf = SynteticID; | ||
} | ||
return StateInfImpl; | ||
}()); | ||
var StateLinkImpl = /** @class */ (function () { | ||
@@ -524,3 +536,3 @@ function StateLinkImpl(state, path, onUpdateUsed, valueUntracked) { | ||
} | ||
function useDerivedStateLink(originLink) { | ||
function useScopedStateLink(originLink) { | ||
var _a = React.useState({}), setValue = _a[1]; | ||
@@ -530,3 +542,2 @@ return useSubscribedStateLink(originLink.state, originLink.path, function () { | ||
}, originLink, originLink.disabledTracking); | ||
// note PrerenderTransform strategy is not inherited intentionally | ||
} | ||
@@ -536,3 +547,3 @@ function useAutoStateLink(initialState) { | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
return useDerivedStateLink(initialState); | ||
return useScopedStateLink(initialState); | ||
} | ||
@@ -576,10 +587,17 @@ if (initialState instanceof StateRefImpl) { | ||
} | ||
/// | ||
/// EXPORTED IMPLEMENTATIONS | ||
/// | ||
function createStateLink(initial) { | ||
return new StateRefImpl(createState(initial)); | ||
function createStateLink(initial, transform) { | ||
var ref = new StateRefImpl(createState(initial)); | ||
if (transform) { | ||
return new StateInfImpl(ref, transform); | ||
} | ||
return ref; | ||
} | ||
function useStateLink(initialState, transform) { | ||
var link = useAutoStateLink(initialState); | ||
function useStateLink(source, transform) { | ||
var state = source instanceof StateInfImpl | ||
? source.wrapped | ||
: source; | ||
var link = useAutoStateLink(state); | ||
if (source instanceof StateInfImpl) { | ||
return injectTransform(link, source.transform); | ||
} | ||
if (transform) { | ||
@@ -590,4 +608,6 @@ return injectTransform(link, transform); | ||
} | ||
function useStateLinkUnmounted(state, transform) { | ||
var stateRef = state; | ||
function useStateLinkUnmounted(source, transform) { | ||
var stateRef = source instanceof StateInfImpl | ||
? source.wrapped | ||
: source; | ||
var link = new StateLinkImpl(stateRef.state, RootPath, | ||
@@ -598,2 +618,5 @@ // it is assumed the client discards the state link once it is used | ||
}, stateRef.state.get(RootPath)).with(DisabledTracking); // it does not matter how it is used, it is not subscribed anyway | ||
if (source instanceof StateInfImpl) { | ||
return source.transform(link, undefined); | ||
} | ||
if (transform) { | ||
@@ -600,0 +623,0 @@ return transform(link); |
import React from 'react'; | ||
export interface PluginTypeMarker<S, E extends {}> { | ||
} | ||
export interface StateRef<S, E extends {}> { | ||
export interface StateRef<S, E extends {} = {}> { | ||
__synteticTypeInferenceMarkerRef: symbol; | ||
with<I>(plugin: (marker: PluginTypeMarker<S, E>) => Plugin<E, I>): StateRef<S, E & I>; | ||
} | ||
export declare type NestedInferredLink<S, E extends {}> = S extends ReadonlyArray<(infer U)> ? ReadonlyArray<StateLink<U, E>> : S extends null ? undefined : S extends object ? { | ||
export interface StateInf<R> { | ||
__synteticTypeInferenceMarkerInf: symbol; | ||
} | ||
export declare type NestedInferredLink<S, E extends {} = {}> = S extends ReadonlyArray<(infer U)> ? ReadonlyArray<StateLink<U, E>> : S extends null ? undefined : S extends object ? { | ||
readonly [K in keyof Required<S>]: StateLink<S[K], E>; | ||
@@ -35,7 +39,10 @@ } : undefined; | ||
export declare function createStateLink<S>(initial: S | (() => S)): StateRef<S, {}>; | ||
export declare function useStateLink<S, E extends {}>(initialState: StateLink<S, E> | StateRef<S, E>): StateLink<S, E>; | ||
export declare function useStateLink<S, E extends {}, R>(initialState: StateLink<S, E> | StateRef<S, E>, transform: (state: StateLink<S, E>, prev: R | undefined) => R): R; | ||
export declare function useStateLink<S>(initialState: S | (() => S)): StateLink<S>; | ||
export declare function useStateLink<S, R>(initialState: S | (() => S), transform: (state: StateLink<S>, prev: R | undefined) => R): R; | ||
export declare function useStateLinkUnmounted<S, E extends {}>(stateRef: StateRef<S, E>): StateLink<S, E>; | ||
export declare function createStateLink<S, R>(initial: S | (() => S), transform: (state: StateLink<S>, prev: R | undefined) => R): StateInf<R>; | ||
export declare function useStateLink<R>(source: StateInf<R>): StateInf<R>; | ||
export declare function useStateLink<S, E extends {}>(source: StateLink<S, E> | StateRef<S, E>): StateLink<S, E>; | ||
export declare function useStateLink<S, E extends {}, R>(source: StateLink<S, E> | StateRef<S, E>, transform: (state: StateLink<S, E>, prev: R | undefined) => R): R; | ||
export declare function useStateLink<S>(source: S | (() => S)): StateLink<S>; | ||
export declare function useStateLink<S, R>(source: S | (() => S), transform: (state: StateLink<S>, prev: R | undefined) => R): R; | ||
export declare function useStateLinkUnmounted<R>(source: StateInf<R>): R; | ||
export declare function useStateLinkUnmounted<S, E extends {}>(source: StateRef<S, E>): StateLink<S, E>; | ||
export declare function DisabledTracking(): Plugin<{}, {}>; | ||
@@ -42,0 +49,0 @@ export interface PrerenderExtensions { |
{ | ||
"name": "@hookstate/core", | ||
"version": "0.10.0", | ||
"description": "Modern and high-performance (data access tracked) state management for react done in type-safe and plugin extandable way.", | ||
"version": "0.10.1", | ||
"description": "Modern and high-performance (data access tracked) state management for react done in type-safe and plugin extendable way.", | ||
"license": "MIT", | ||
@@ -10,8 +10,8 @@ "author": { | ||
"repository": { | ||
"url": "https://github.com/avkonst/react-hookstate" | ||
"url": "https://github.com/avkonst/hookstate" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/avkonst/react-hookstate/issues" | ||
"url": "https://github.com/avkonst/hookstate/issues" | ||
}, | ||
"homepage": "https://github.com/avkonst/react-hookstate", | ||
"homepage": "https://github.com/avkonst/hookstate", | ||
"main": "dist/index.js", | ||
@@ -18,0 +18,0 @@ "module": "dist/index.es.js", |
# @hookstate/core | ||
Modern and high-performance (data access tracked) state management for react done in type-safe and plugin extandable way. | ||
Modern and high-performance (data access tracked) state management for react done in type-safe and plugin extendable way. | ||
## Why Hookstate | ||
To be done | ||
## API Documentation | ||
To be done. | ||
## Plugins | ||
To be done. |
Sorry, the diff of this file is not supported yet
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the 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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
170156
1330
16
9