Comparing version 0.4.7 to 0.4.8
import { FC } from 'react'; | ||
import { expr, box, sel, transaction } from 'reactive-box'; | ||
export { prop, cache, action, on, cycle, effect, shared, initial, observe, useValue, useLocal, useShared, free, mock, box, sel, expr, transaction, Ensurable, }; | ||
export { prop, cache, action, on, cycle, effect, shared, initial, observe, useValue, useLocal, useShared, free, mock, box, sel, expr, transaction, boxProperty, selProperty, Ensurable, }; | ||
declare type Ensurable<T> = T | void; | ||
@@ -31,3 +31,5 @@ declare function action<T = undefined>(init?: T): { | ||
declare function free(): void; | ||
declare function boxProperty(o: any, p: string | number | symbol, init?: any): any; | ||
declare function selProperty(o: any, p: string | number | symbol, selector: () => any): any; | ||
declare function prop(_proto: any, key: any, descriptor?: any): any; | ||
declare function cache(_proto: any, key: any, descriptor: any): any; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.transaction = exports.expr = exports.sel = exports.box = exports.mock = exports.free = exports.useShared = exports.useLocal = exports.useValue = exports.observe = exports.initial = exports.shared = exports.effect = exports.cycle = exports.on = exports.action = exports.cache = exports.prop = void 0; | ||
exports.selProperty = exports.boxProperty = exports.transaction = exports.expr = exports.sel = exports.box = exports.mock = exports.free = exports.useShared = exports.useLocal = exports.useValue = exports.observe = exports.initial = exports.shared = exports.effect = exports.cycle = exports.on = exports.action = exports.cache = exports.prop = void 0; | ||
const react_1 = require("react"); | ||
@@ -177,14 +177,23 @@ const reactive_box_1 = require("reactive-box"); | ||
exports.free = free; | ||
function boxProperty(target, key, initializer) { | ||
const [get, set] = reactive_box_1.box(initializer && initializer()); | ||
Object.defineProperty(target, key, { get, set }); | ||
function boxProperty(o, p, init) { | ||
const [get, set] = reactive_box_1.box(init); | ||
Object.defineProperty(o, p, { get, set }); | ||
return o; | ||
} | ||
exports.boxProperty = boxProperty; | ||
function selProperty(o, p, selector) { | ||
const [get] = reactive_box_1.sel(selector); | ||
Object.defineProperty(o, p, { get }); | ||
return o; | ||
} | ||
exports.selProperty = selProperty; | ||
function prop(_proto, key, descriptor) { | ||
const initializer = descriptor === null || descriptor === void 0 ? void 0 : descriptor.initializer; | ||
return { | ||
get() { | ||
boxProperty(this, key, descriptor === null || descriptor === void 0 ? void 0 : descriptor.initializer); | ||
boxProperty(this, key, initializer && initializer()); | ||
return this[key]; | ||
}, | ||
set(value) { | ||
boxProperty(this, key, descriptor === null || descriptor === void 0 ? void 0 : descriptor.initializer); | ||
boxProperty(this, key, initializer && initializer()); | ||
this[key] = value; | ||
@@ -198,4 +207,3 @@ }, | ||
get() { | ||
const [get] = reactive_box_1.sel(descriptor.get); | ||
Object.defineProperty(this, key, { get }); | ||
selProperty(this, key, descriptor.get); | ||
return this[key]; | ||
@@ -202,0 +210,0 @@ }, |
{ | ||
"name": "realar", | ||
"version": "0.4.7", | ||
"version": "0.4.8", | ||
"description": "React state manager", | ||
@@ -91,3 +91,3 @@ "repository": { | ||
}, | ||
"gitHead": "c236de18db19744004b8ef12c925982602abbd5a" | ||
"gitHead": "f23db327e49eb65f11243386a1124379e06e7531" | ||
} |
@@ -69,3 +69,3 @@ # Realar | ||
_Documentation not ready yet for `action`, `cache`, `on`, `cycle`, `effect`, `shared`, `initial`, `mock`, `free`, `useLocal`, `observe`, `useValue`, `useShared`, `transaction`, `box`, `sel` functions. It's coming soon._ | ||
_Documentation not ready yet for `action`, `cache`, `on`, `cycle`, `effect`, `shared`, `initial`, `mock`, `free`, `useLocal`, `observe`, `useValue`, `useShared`, `transaction`, `box`, `sel`, `boxProperty`, `selProperty` functions. It's coming soon._ | ||
@@ -72,0 +72,0 @@ ### Demos |
@@ -29,2 +29,4 @@ import { useRef, useReducer, useEffect, useMemo, FC } from 'react'; | ||
transaction, | ||
boxProperty, | ||
selProperty, | ||
Ensurable, | ||
@@ -218,15 +220,23 @@ }; | ||
function boxProperty(target: any, key: any, initializer: any) { | ||
const [get, set] = box(initializer && initializer()); | ||
Object.defineProperty(target, key, { get, set }); | ||
function boxProperty(o: any, p: string | number | symbol, init?: any): any { | ||
const [get, set] = box(init); | ||
Object.defineProperty(o, p, { get, set }); | ||
return o; | ||
} | ||
function selProperty(o: any, p: string | number | symbol, selector: () => any): any { | ||
const [get] = sel(selector); | ||
Object.defineProperty(o, p, { get }); | ||
return o; | ||
} | ||
function prop(_proto: any, key: any, descriptor?: any): any { | ||
const initializer = descriptor?.initializer; | ||
return { | ||
get() { | ||
boxProperty(this, key, descriptor?.initializer); | ||
boxProperty(this, key, initializer && initializer()); | ||
return this[key]; | ||
}, | ||
set(value: any) { | ||
boxProperty(this, key, descriptor?.initializer); | ||
boxProperty(this, key, initializer && initializer()); | ||
this[key] = value; | ||
@@ -240,4 +250,3 @@ }, | ||
get() { | ||
const [get] = sel(descriptor.get); | ||
Object.defineProperty(this, key, { get }); | ||
selProperty(this, key, descriptor.get); | ||
return this[key]; | ||
@@ -244,0 +253,0 @@ }, |
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
27295
466