File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { Draft } from 'immer' ;
2+
13declare function ripplePrimitive < T > ( initial : T ) : RippleInterface < T > ;
24
5+ interface RippleWithImmerUpdate < T > extends RippleInterface < T > {
6+ update ( recipe : ( draft : Draft < T > ) => void | Promise < void > ) : Promise < void > ;
7+ }
38interface RippleInterface < T > {
49 value : T ;
510 subscribe : ( cb : ( ) => void , selector ?: ( v : T ) => unknown ) => ( ) => void ;
@@ -10,6 +15,7 @@ interface RippleFunctionInterface {
1015 < T > ( initial : T ) : RippleInterface < T > ;
1116 proxy : < T extends object > ( initial : T ) => RippleInterface < T > ;
1217 primitive : typeof ripplePrimitive ;
18+ immer : < T extends object > ( initial : T ) => RippleWithImmerUpdate < T > ;
1319}
1420
1521type HandlerType = ( payload ?: any , tools ?: {
Original file line number Diff line number Diff line change 1+ import { Draft } from 'immer' ;
2+
13declare function ripplePrimitive < T > ( initial : T ) : RippleInterface < T > ;
24
5+ interface RippleWithImmerUpdate < T > extends RippleInterface < T > {
6+ update ( recipe : ( draft : Draft < T > ) => void | Promise < void > ) : Promise < void > ;
7+ }
38interface RippleInterface < T > {
49 value : T ;
510 subscribe : ( cb : ( ) => void , selector ?: ( v : T ) => unknown ) => ( ) => void ;
@@ -10,6 +15,7 @@ interface RippleFunctionInterface {
1015 < T > ( initial : T ) : RippleInterface < T > ;
1116 proxy : < T extends object > ( initial : T ) => RippleInterface < T > ;
1217 primitive : typeof ripplePrimitive ;
18+ immer : < T extends object > ( initial : T ) => RippleWithImmerUpdate < T > ;
1319}
1420
1521type HandlerType = ( payload ?: any , tools ?: {
Load Diff Large diffs are not rendered by default.
Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change 1212 "devDependencies" : {
1313 "@preact/signals" : " ^2.2.0" ,
1414 "@types/react" : " ^19.1.8" ,
15+ "prettier" : " 3.6.2" ,
1516 "react" : " ^19.1.0" ,
1617 "react-dom" : " ^19.1.0" ,
1718 "tsup" : " ^8.5.0" ,
1819 "typescript" : " ^5.8.3" ,
19- "prettier " : " 3.6.2 "
20+ "immer " : " ^10.1.1 "
2021 },
2122 "exports" : {
2223 "." : {
Original file line number Diff line number Diff line change 1- export { computed , effect } from "@preact/signals" ;
21import {
32 RippleFunctionInterface ,
43 RippleInterface ,
54} from "../interfaces/ripple.interface" ;
65import { ripplePrimitive } from "../utils/ripplePrimitive" ;
76import { rippleObject } from "../utils/rippleObject" ;
87import { rippleProxy } from "../utils/rippleProxy" ;
8+ import { createImmerStore } from "../utils/immer" ;
99
1010export const ripple = function < T > ( initial : T ) : RippleInterface < T > {
1111 return isObject ( initial ) ? rippleObject ( initial ) : ripplePrimitive ( initial ) ;
1212} as RippleFunctionInterface ;
1313
14- function isObject ( value : unknown ) : value is object | Array < any > {
15- return ( typeof value === "object" && value !== null ) || Array . isArray ( value ) ;
14+ function isObject ( value : unknown ) : value is object | any [ ] {
15+ return typeof value === "object" && value !== null ;
1616}
1717
1818Object . assign ( ripple , {
1919 proxy : rippleProxy ,
2020 primitive : ripplePrimitive ,
2121 object : rippleObject ,
22+ immer : createImmerStore ,
2223} ) ;
Original file line number Diff line number Diff line change 11import { ripplePrimitive } from "../utils/ripplePrimitive" ;
2+ import type { Draft } from "immer" ;
3+
4+ interface RippleWithImmerUpdate < T > extends RippleInterface < T > {
5+ update ( recipe : ( draft : Draft < T > ) => void | Promise < void > ) : Promise < void > ;
6+ }
27
38export interface RippleInterface < T > {
49 value : T ;
@@ -11,4 +16,5 @@ export interface RippleFunctionInterface {
1116 < T > ( initial : T ) : RippleInterface < T > ;
1217 proxy : < T extends object > ( initial : T ) => RippleInterface < T > ;
1318 primitive : typeof ripplePrimitive ;
19+ immer : < T extends object > ( initial : T ) => RippleWithImmerUpdate < T > ;
1420}
Original file line number Diff line number Diff line change 1+ import { ripplePrimitive } from "./ripplePrimitive" ;
2+ import { produce , Draft } from "immer" ;
3+
4+ export function createImmerStore < T extends object > ( initial : T ) {
5+ const root = ripplePrimitive < T > ( initial ) ;
6+
7+ function update ( recipe : ( draft : Draft < T > ) => void ) {
8+ const next = produce ( root . value , recipe ) ;
9+ if ( next !== root . value ) root . value = next ;
10+ }
11+
12+ return Object . assign ( root , { update } ) ;
13+ }
You can’t perform that action at this time.
0 commit comments