Comparing version 0.5.2 to 0.5.3
@@ -90,5 +90,3 @@ "use strict"; | ||
is_sync = 0; | ||
if (!target) | ||
return; | ||
else if (target[0]) { | ||
if (target[0]) { | ||
target = target[0]; // box or selector or custom reactive | ||
@@ -203,3 +201,2 @@ } | ||
exports.useScoped = useScoped; | ||
; | ||
const Scope = ({ children }) => { | ||
@@ -206,0 +203,0 @@ const h = useMemo(() => [new Map(), []], []); |
{ | ||
"name": "realar", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"description": "React state manager", | ||
@@ -30,3 +30,3 @@ "repository": { | ||
"dependencies": { | ||
"reactive-box": ">=0.6.2 <=0.6.x" | ||
"reactive-box": ">=0.6.3 <=0.6.x" | ||
}, | ||
@@ -89,3 +89,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "8583f65836ca49aa79e31b47d4f3769e98457f9f" | ||
"gitHead": "d6a5fea76cf20eafe7dcd47fdf1f8841c9186017" | ||
} |
@@ -158,3 +158,26 @@ # Realar | ||
Usually, signal subscription (_by `on` function_) very comfortable coding in class constructors. | ||
```javascript | ||
const startAnimation = signal(); | ||
class Animation { | ||
constructor() { | ||
on(startAnimation, this.start); | ||
} | ||
start = async () => { | ||
console.log('animation starting...'); | ||
} | ||
} | ||
shared(Animation); | ||
startAnimation(); | ||
``` | ||
[Edit on RunKit](https://runkit.com/betula/602f62db23b6cd001adc5dfa) | ||
If you making an instance of a class with a subscription in the constructor, though `shared`, `useLocal`, `useScoped` Realar functions, It will be unsubscribed automatically. | ||
Below other examples | ||
```javascript | ||
const add = signal(); | ||
@@ -361,3 +384,3 @@ | ||
_Documentation not ready yet for `sel`, `effect`, `initial`, `mock`, `unmock`, `free`, `cache`, `observe`, `transaction`, `untrack` functions. It's coming soon._ | ||
_Documentation not ready yet for `selector`, `effect`, `initial`, `mock`, `unmock`, `free`, `cache`, `observe`, `transaction`, `untrack` functions. It's coming soon._ | ||
@@ -384,3 +407,3 @@ ### Demos | ||
**If you like OOP** update your babel config for support class decorators and using [babel plugin](https://github.com/betula/babel-plugin-realar) for automatic observation arrow function components. | ||
And update your babel config for support class decorators and using [babel plugin](https://github.com/betula/babel-plugin-realar) for automatic observation arrow function components. | ||
@@ -387,0 +410,0 @@ ```javascript |
@@ -160,6 +160,3 @@ import React, { Context, FC } from 'react'; | ||
): () => void; | ||
function on<T>( | ||
target: Reactionable<T>, | ||
listener: (value: T, prev?: T) => void | ||
): () => void; | ||
function on<T>(target: Reactionable<T>, listener: (value: T, prev?: T) => void): () => void; | ||
function on(target: any, listener: (value: any, prev?: any) => void): () => void { | ||
@@ -171,4 +168,3 @@ const sync_mode = is_sync; | ||
if (!target) return; | ||
else if (target[0]) { | ||
if (target[0]) { | ||
target = target[0]; // box or selector or custom reactive | ||
@@ -195,6 +191,3 @@ } else { | ||
function sync<T>( | ||
target: Reactionable<T>, | ||
listener: (value: T, prev?: T) => void | ||
): () => void { | ||
function sync<T>(target: Reactionable<T>, listener: (value: T, prev?: T) => void): () => void { | ||
is_sync = 1; | ||
@@ -276,5 +269,3 @@ return on(target, listener); | ||
function useScoped<M>( | ||
target: | ||
| (new (init?: any) => M | Reactionable<M>) | ||
| ((init?: any) => M | Reactionable<M>) | ||
target: (new (init?: any) => M | Reactionable<M>) | ((init?: any) => M | Reactionable<M>) | ||
): M { | ||
@@ -297,3 +288,3 @@ const context_data = useContext(get_scope_context()); | ||
return useValue(instance); | ||
}; | ||
} | ||
@@ -328,5 +319,3 @@ const Scope: FC = ({ children }) => { | ||
function useLocal<T extends unknown[], M>( | ||
target: | ||
| (new (...args: T) => M | Reactionable<M>) | ||
| ((...args: T) => M | Reactionable<M>), | ||
target: (new (...args: T) => M | Reactionable<M>) | ((...args: T) => M | Reactionable<M>), | ||
deps = [] as T | ||
@@ -370,5 +359,3 @@ ): M { | ||
function useShared<M>( | ||
target: | ||
| (new (init?: any) => M | Reactionable<M>) | ||
| ((init?: any) => M | Reactionable<M>) | ||
target: (new (init?: any) => M | Reactionable<M>) | ((init?: any) => M | Reactionable<M>) | ||
): M { | ||
@@ -375,0 +362,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
46945
425
694
Updatedreactive-box@>=0.6.3 <=0.6.x