effect-lens 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -12
- package/dist/Lens.d.ts +22 -7
- package/dist/Lens.js +12 -3
- package/dist/Lens.js.map +1 -1
- package/dist/Subscribable.d.ts +31 -0
- package/dist/Subscribable.js +19 -0
- package/dist/Subscribable.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +13 -11
package/README.md
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
A Lens type for [Effect](https://effect.website/) to easily manage nested state.
|
|
4
4
|
|
|
5
|
-
A proper documentation is currently being written. In the meantime, you can take a look at the quickstart below and at the `packages/example` directory.
|
|
6
|
-
|
|
7
5
|
## Install
|
|
8
6
|
```
|
|
9
7
|
npm install effect-lens
|
|
@@ -140,7 +138,7 @@ const ref = yield* SubscriptionRef.make<{
|
|
|
140
138
|
// \/ Lens<User, NoSuchElementException, NoSuchElementException, never, never>
|
|
141
139
|
const jeanDupontLens = ref.pipe(
|
|
142
140
|
Lens.fromSubscriptionRef, // Creates a lens that proxies the ref
|
|
143
|
-
Lens.
|
|
141
|
+
Lens.focusObjectField("users"), // Creates a focused lens that points to the users field
|
|
144
142
|
Lens.focusArrayAt(0), // Creates a focused lens that points to the first entry of the user array
|
|
145
143
|
)
|
|
146
144
|
// Reading or writing from this lense can fail with NoSuchElementException
|
|
@@ -150,7 +148,7 @@ const jeanDupont = yield* Lens.get(jeanDupontLens)
|
|
|
150
148
|
|
|
151
149
|
yield* Lens.set(
|
|
152
150
|
// You can focus even further down
|
|
153
|
-
Lens.
|
|
151
|
+
Lens.focusObjectField(jeanDupontLens, "age"),
|
|
154
152
|
yield* DateTime.make("03/25/1970"),
|
|
155
153
|
)
|
|
156
154
|
// Mutations with the parent state are performed immutably by default
|
|
@@ -160,10 +158,12 @@ yield* Lens.set(
|
|
|
160
158
|
Currently available:
|
|
161
159
|
| Name | Description | Parent state mutation behavior | Notes |
|
|
162
160
|
| - | - | - | - |
|
|
163
|
-
| `
|
|
164
|
-
| `
|
|
161
|
+
| `focusObjectField` | Focuses to the field of an object. Replaces the parent object immutably when writing to the focused field | Immutable | |
|
|
162
|
+
| `focusObjectMutableField` | Focuses to the writable field of an object. Mutates the parent object in place via the writable field | Mutable | Type-safe: will not allow you to mutate `readonly` fields |
|
|
165
163
|
| `focusArrayAt` | Focuses to an indexed entry of an array. Replaces the parent array immutably when writing to the focused index | Immutable | |
|
|
166
164
|
| `focusMutableArrayAt` | Focuses to an indexed entry of an array. Mutates the parent array in place at the focused index | Mutable | Type-safe: will not allow you to mutate `readonly` arrays |
|
|
165
|
+
| `focusTupleAt` | Focuses to an indexed entry of a readonly tuple. Replaces the parent tuple immutably when writing to the focused index | Immutable | |
|
|
166
|
+
| `focusMutableTupleAt` | Focuses to an indexed entry of a mutable tuple. Mutates the parent tuple in place at the focused index | Mutable | Type-safe: will not allow you to mutate `readonly` tuples |
|
|
167
167
|
| `focusChunkAt` | Focuses to an indexed entry of a `Chunk`. Replaces the parent `Chunk` immutably when writing to the focused element | Immutable | |
|
|
168
168
|
|
|
169
169
|
Also more to come!
|
|
@@ -171,11 +171,6 @@ Also more to come!
|
|
|
171
171
|
#### Manually
|
|
172
172
|
You can create focused Lenses by composing them manually using `map`, `mapEffect` and `unwrap`:
|
|
173
173
|
```typescript
|
|
174
|
-
interface User {
|
|
175
|
-
readonly name: string
|
|
176
|
-
readonly age: DateTime.Utc
|
|
177
|
-
}
|
|
178
|
-
|
|
179
174
|
const ref = yield* SubscriptionRef.make<readonly User[]>([
|
|
180
175
|
{ name: "Jean Dupont", age: yield* DateTime.make("03/25/1969") },
|
|
181
176
|
{ name: "Juan Joya Borja", age: yield* DateTime.make("04/05/1956") },
|
|
@@ -221,11 +216,33 @@ const someFunctionThatShouldOnlyHaveReadonlyAccessToTheState = (
|
|
|
221
216
|
|
|
222
217
|
const lens = ref.pipe(
|
|
223
218
|
Lens.fromSubscriptionRef,
|
|
224
|
-
Lens.
|
|
219
|
+
Lens.focusObjectField("users"),
|
|
225
220
|
)
|
|
226
221
|
yield* someFunctionThatShouldOnlyHaveReadonlyAccessToTheState(lens)
|
|
227
222
|
```
|
|
228
223
|
|
|
224
|
+
#### Focusing
|
|
225
|
+
This library re-exports Effect's `Subscribable` module and adds a few transforms to narrow the focus of `Subscribable`'s, same as Lenses:
|
|
226
|
+
```typescript
|
|
227
|
+
import { Subscribable } from "effect-lens"
|
|
228
|
+
|
|
229
|
+
declare const sub: Subscribabe.Subscribable<readonly { name: string }[], never, never>
|
|
230
|
+
|
|
231
|
+
// \/ Subscribabe.Subscribable<string, NoSuchElementException, never>
|
|
232
|
+
const nameSub = sub.pipe(
|
|
233
|
+
Subscribable.focusArrayAt(1),
|
|
234
|
+
Subscribable.focusObjectField("name"),
|
|
235
|
+
)
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Currently available:
|
|
239
|
+
| Name | Description |
|
|
240
|
+
| - | - |
|
|
241
|
+
| `focusObjectField` | Focuses to the field of an object |
|
|
242
|
+
| `focusArrayAt` | Focuses to an indexed entry of an array |
|
|
243
|
+
| `focusTupleAt` | Focuses to an indexed entry of a tuple |
|
|
244
|
+
| `focusChunkAt` | Focuses to an indexed entry of a `Chunk` |
|
|
245
|
+
|
|
229
246
|
|
|
230
247
|
## Todo
|
|
231
248
|
|
package/dist/Lens.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Chunk, Effect, Pipeable, Readable, Stream,
|
|
1
|
+
import { Chunk, Effect, Pipeable, Readable, Stream, type SubscriptionRef, type SynchronizedRef } from "effect";
|
|
2
2
|
import type { NoSuchElementException } from "effect/Cause";
|
|
3
|
+
import * as Subscribable from "./Subscribable.js";
|
|
3
4
|
export declare const LensTypeId: unique symbol;
|
|
4
5
|
export type LensTypeId = typeof LensTypeId;
|
|
5
6
|
/**
|
|
@@ -82,11 +83,11 @@ export declare const mapStream: {
|
|
|
82
83
|
/**
|
|
83
84
|
* Narrows the focus to a field of an object. Replaces the object in an immutable fashion when written to.
|
|
84
85
|
*/
|
|
85
|
-
export declare const
|
|
86
|
+
export declare const focusObjectField: {
|
|
86
87
|
<A extends object, K extends keyof A, ER, EW, RR, RW>(self: Lens<A, ER, EW, RR, RW>, key: K): Lens<A[K], ER, EW, RR, RW>;
|
|
87
88
|
<A extends object, K extends keyof A, ER, EW, RR, RW>(key: K): (self: Lens<A, ER, EW, RR, RW>) => Lens<A[K], ER, EW, RR, RW>;
|
|
88
89
|
};
|
|
89
|
-
export declare namespace
|
|
90
|
+
export declare namespace focusObjectMutableField {
|
|
90
91
|
type WritableKeys<T> = {
|
|
91
92
|
[K in keyof T]-?: IfEquals<{
|
|
92
93
|
[P in K]: T[K];
|
|
@@ -99,15 +100,15 @@ export declare namespace focusMutableField {
|
|
|
99
100
|
/**
|
|
100
101
|
* Narrows the focus to a mutable field of an object. Mutates the object in place when written to.
|
|
101
102
|
*/
|
|
102
|
-
export declare const
|
|
103
|
-
<A extends object, K extends
|
|
104
|
-
<A extends object, K extends
|
|
103
|
+
export declare const focusObjectMutableField: {
|
|
104
|
+
<A extends object, K extends focusObjectMutableField.WritableKeys<A>, ER, EW, RR, RW>(self: Lens<A, ER, EW, RR, RW>, key: K): Lens<A[K], ER, EW, RR, RW>;
|
|
105
|
+
<A extends object, K extends focusObjectMutableField.WritableKeys<A>, ER, EW, RR, RW>(key: K): (self: Lens<A, ER, EW, RR, RW>) => Lens<A[K], ER, EW, RR, RW>;
|
|
105
106
|
};
|
|
106
107
|
/**
|
|
107
108
|
* Narrows the focus to an indexed element of an array. Replaces the array in an immutable fashion when written to.
|
|
108
109
|
*/
|
|
109
110
|
export declare const focusArrayAt: {
|
|
110
|
-
<A extends readonly any[], ER, EW, RR, RW>(self: Lens<A, ER, EW, RR, RW>, index: number): Lens<A[number]>;
|
|
111
|
+
<A extends readonly any[], ER, EW, RR, RW>(self: Lens<A, ER, EW, RR, RW>, index: number): Lens<A[number], ER | NoSuchElementException, EW | NoSuchElementException, RR, RW>;
|
|
111
112
|
<A extends readonly any[], ER, EW, RR, RW>(index: number): (self: Lens<A, ER, EW, RR, RW>) => Lens<A[number], ER | NoSuchElementException, EW | NoSuchElementException, RR, RW>;
|
|
112
113
|
};
|
|
113
114
|
/**
|
|
@@ -117,6 +118,20 @@ export declare const focusMutableArrayAt: {
|
|
|
117
118
|
<A, ER, EW, RR, RW>(self: Lens<A[], ER, EW, RR, RW>, index: number): Lens<A, ER | NoSuchElementException, EW | NoSuchElementException, RR, RW>;
|
|
118
119
|
<A, ER, EW, RR, RW>(index: number): (self: Lens<A[], ER, EW, RR, RW>) => Lens<A, ER | NoSuchElementException, EW | NoSuchElementException, RR, RW>;
|
|
119
120
|
};
|
|
121
|
+
/**
|
|
122
|
+
* Narrows the focus to an indexed element of a readonly tuple. Replaces the tuple in an immutable fashion when written to.
|
|
123
|
+
*/
|
|
124
|
+
export declare const focusTupleAt: {
|
|
125
|
+
<T extends readonly [any, ...any[]], I extends number, ER, EW, RR, RW>(self: Lens<T, ER, EW, RR, RW>, index: I): Lens<T[I], ER, EW, RR, RW>;
|
|
126
|
+
<T extends readonly [any, ...any[]], I extends number, ER, EW, RR, RW>(index: I): (self: Lens<T, ER, EW, RR, RW>) => Lens<T[I], ER, EW, RR, RW>;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Narrows the focus to an indexed element of a mutable tuple. Mutates the tuple in place when written to.
|
|
130
|
+
*/
|
|
131
|
+
export declare const focusMutableTupleAt: {
|
|
132
|
+
<T extends [any, ...any[]], I extends number, ER, EW, RR, RW>(self: Lens<T, ER, EW, RR, RW>, index: I): Lens<T[I], ER, EW, RR, RW>;
|
|
133
|
+
<T extends [any, ...any[]], I extends number, ER, EW, RR, RW>(index: I): (self: Lens<T, ER, EW, RR, RW>) => Lens<T[I], ER, EW, RR, RW>;
|
|
134
|
+
};
|
|
120
135
|
/**
|
|
121
136
|
* Narrows the focus to an indexed element of `Chunk`. Replaces the `Chunk` in an immutable fashion when written to.
|
|
122
137
|
*/
|
package/dist/Lens.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Array, Chunk, Effect, Function, Pipeable, Predicate, Readable, Stream
|
|
1
|
+
import { Array, Chunk, Effect, Function, Pipeable, Predicate, Readable, Stream } from "effect";
|
|
2
|
+
import * as Subscribable from "./Subscribable.js";
|
|
2
3
|
export const LensTypeId = Symbol.for("@effect-fc/Lens/Lens");
|
|
3
4
|
/**
|
|
4
5
|
* Internal `Lens` implementation.
|
|
@@ -83,11 +84,11 @@ export const mapStream = Function.dual(2, (self, f) => make({
|
|
|
83
84
|
/**
|
|
84
85
|
* Narrows the focus to a field of an object. Replaces the object in an immutable fashion when written to.
|
|
85
86
|
*/
|
|
86
|
-
export const
|
|
87
|
+
export const focusObjectField = Function.dual(2, (self, key) => map(self, a => a[key], (a, b) => Object.setPrototypeOf({ ...a, [key]: b }, Object.getPrototypeOf(a))));
|
|
87
88
|
/**
|
|
88
89
|
* Narrows the focus to a mutable field of an object. Mutates the object in place when written to.
|
|
89
90
|
*/
|
|
90
|
-
export const
|
|
91
|
+
export const focusObjectMutableField = Function.dual(2, (self, key) => map(self, a => a[key], (a, b) => { a[key] = b; return a; }));
|
|
91
92
|
/**
|
|
92
93
|
* Narrows the focus to an indexed element of an array. Replaces the array in an immutable fashion when written to.
|
|
93
94
|
*/
|
|
@@ -96,6 +97,14 @@ export const focusArrayAt = Function.dual(2, (self, index) => mapEffect(self, Ar
|
|
|
96
97
|
* Narrows the focus to an indexed element of a mutable array. Mutates the array in place when written to.
|
|
97
98
|
*/
|
|
98
99
|
export const focusMutableArrayAt = Function.dual(2, (self, index) => mapEffect(self, Array.get(index), (a, b) => Effect.flatMap(Array.get(a, index), () => Effect.as(Effect.sync(() => { a[index] = b; }), a))));
|
|
100
|
+
/**
|
|
101
|
+
* Narrows the focus to an indexed element of a readonly tuple. Replaces the tuple in an immutable fashion when written to.
|
|
102
|
+
*/
|
|
103
|
+
export const focusTupleAt = Function.dual(2, (self, index) => map(self, Array.unsafeGet(index), (a, b) => Array.replace(a, index, b)));
|
|
104
|
+
/**
|
|
105
|
+
* Narrows the focus to an indexed element of a mutable tuple. Mutates the tuple in place when written to.
|
|
106
|
+
*/
|
|
107
|
+
export const focusMutableTupleAt = Function.dual(2, (self, index) => map(self, Array.unsafeGet(index), (a, b) => { a[index] = b; return a; }));
|
|
99
108
|
/**
|
|
100
109
|
* Narrows the focus to an indexed element of `Chunk`. Replaces the `Chunk` in an immutable fashion when written to.
|
|
101
110
|
*/
|
package/dist/Lens.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Lens.js","sourceRoot":"","sources":["../src/Lens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"Lens.js","sourceRoot":"","sources":["../src/Lens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAA8C,MAAM,QAAQ,CAAA;AAE1I,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AAGjD,MAAM,CAAC,MAAM,UAAU,GAAkB,MAAM,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAA;AAmB3E;;GAEG;AACH,MAAM,OAAO,QACT,SAAQ,QAAQ,CAAC,KAAK,EAAE;IAMX;IACA;IACA;IAPJ,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAoB,QAAQ,CAAC,MAAM,CAAA;IACpD,CAAC,YAAY,CAAC,MAAM,CAAC,GAAwB,YAAY,CAAC,MAAM,CAAA;IAChE,CAAC,UAAU,CAAC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SAAS,GAGlB,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAoB,IAA6B,EAAE,KAAQ,EAAE,EAAE,CAChF,IAAI,CAAC,MAAM,CAAkB,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,CAAU,CAAC,CAAC,CAC9E,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAGrB,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAoB,IAA6B,EAAE,CAAc,EAAE,EAAE,CACtF,IAAI,CAAC,MAAM,CAAkB,CAAC,CAAC,EAAE;IAC7B,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;IACjB,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,IAAI,CAAU,CAAC,CAAA;AAChD,CAAC,CAAC,CACL,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAG3B,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAA0B,IAA6B,EAAE,CAAmC,EAAE,EAAE,CACjH,IAAI,CAAC,MAAM,CAAU,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,CACpC,CAAC,CAAC,CAAC,CAAC,EACJ,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,IAAI,CAAU,CAAC,CAChD,CAAC,CACL,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Chunk, Subscribable } from "effect";
|
|
2
|
+
import type { NoSuchElementException } from "effect/Cause";
|
|
3
|
+
export * from "effect/Subscribable";
|
|
4
|
+
/**
|
|
5
|
+
* Narrows the focus to a field of an object.
|
|
6
|
+
*/
|
|
7
|
+
export declare const focusObjectField: {
|
|
8
|
+
<A extends object, K extends keyof A, E, R>(self: Subscribable.Subscribable<A, E, R>, key: K): Subscribable.Subscribable<A[K], E, R>;
|
|
9
|
+
<A extends object, K extends keyof A, E, R>(key: K): (self: Subscribable.Subscribable<A, E, R>) => Subscribable.Subscribable<A[K], E, R>;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Narrows the focus to an indexed element of an array.
|
|
13
|
+
*/
|
|
14
|
+
export declare const focusArrayAt: {
|
|
15
|
+
<A extends readonly any[], E, R>(self: Subscribable.Subscribable<A, E, R>, index: number): Subscribable.Subscribable<A[number], E, R>;
|
|
16
|
+
<A extends readonly any[], E, R>(index: number): (self: Subscribable.Subscribable<A, E, R>) => Subscribable.Subscribable<A[number], E | NoSuchElementException, R>;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Narrows the focus to an indexed element of a readonly tuple.
|
|
20
|
+
*/
|
|
21
|
+
export declare const focusTupleAt: {
|
|
22
|
+
<T extends readonly [any, ...any[]], I extends number, E, R>(self: Subscribable.Subscribable<T, E, R>, index: I): Subscribable.Subscribable<T[I], E, R>;
|
|
23
|
+
<T extends readonly [any, ...any[]], I extends number, E, R>(index: I): (self: Subscribable.Subscribable<T, E, R>) => Subscribable.Subscribable<T[I], E, R>;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Narrows the focus to an indexed element of `Chunk`.
|
|
27
|
+
*/
|
|
28
|
+
export declare const focusChunkAt: {
|
|
29
|
+
<A, E, R>(self: Subscribable.Subscribable<Chunk.Chunk<A>, E, R>, index: number): Subscribable.Subscribable<A, E | NoSuchElementException, R>;
|
|
30
|
+
<A, E, R>(index: number): (self: Subscribable.Subscribable<Chunk.Chunk<A>, E, R>) => Subscribable.Subscribable<A, E | NoSuchElementException, R>;
|
|
31
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Array, Chunk, Function, Subscribable } from "effect";
|
|
2
|
+
export * from "effect/Subscribable";
|
|
3
|
+
/**
|
|
4
|
+
* Narrows the focus to a field of an object.
|
|
5
|
+
*/
|
|
6
|
+
export const focusObjectField = Function.dual(2, (self, key) => Subscribable.map(self, a => a[key]));
|
|
7
|
+
/**
|
|
8
|
+
* Narrows the focus to an indexed element of an array.
|
|
9
|
+
*/
|
|
10
|
+
export const focusArrayAt = Function.dual(2, (self, index) => Subscribable.mapEffect(self, Array.get(index)));
|
|
11
|
+
/**
|
|
12
|
+
* Narrows the focus to an indexed element of a readonly tuple.
|
|
13
|
+
*/
|
|
14
|
+
export const focusTupleAt = Function.dual(2, (self, index) => Subscribable.map(self, Array.unsafeGet(index)));
|
|
15
|
+
/**
|
|
16
|
+
* Narrows the focus to an indexed element of `Chunk`.
|
|
17
|
+
*/
|
|
18
|
+
export const focusChunkAt = Function.dual(2, (self, index) => Subscribable.mapEffect(self, Chunk.get(index)));
|
|
19
|
+
//# sourceMappingURL=Subscribable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Subscribable.js","sourceRoot":"","sources":["../src/Subscribable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAI7D,cAAc,qBAAqB,CAAA;AAEnC;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAQzB,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CACjB,IAAwC,EACxC,GAAM,EAC+B,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;AAEhF;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAQrB,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CACjB,IAAwC,EACxC,KAAa,EACsD,EAAE,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAEzH;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAQrB,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CACjB,IAAwC,EACxC,KAAQ,EAC6B,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAE3F;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAQrB,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CACjB,IAAqD,EACrD,KAAa,EAC8C,EAAE,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AACjD,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "effect-lens",
|
|
3
3
|
"description": "An effectful Lens type to easily manage nested state",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"./README.md",
|
|
@@ -17,16 +17,18 @@
|
|
|
17
17
|
"types": "./dist/index.d.ts",
|
|
18
18
|
"default": "./dist/index.js"
|
|
19
19
|
},
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
"./Lens": {
|
|
21
|
+
"types": "./dist/Lens.d.ts",
|
|
22
|
+
"default": "./dist/Lens.js"
|
|
23
|
+
},
|
|
24
|
+
"./PropertyPath": {
|
|
25
|
+
"types": "./dist/PropertyPath.d.ts",
|
|
26
|
+
"default": "./dist/PropertyPath.js"
|
|
27
|
+
},
|
|
28
|
+
"./Subscribable": {
|
|
29
|
+
"types": "./dist/Subscribable.d.ts",
|
|
30
|
+
"default": "./dist/Subscribable.js"
|
|
31
|
+
}
|
|
30
32
|
},
|
|
31
33
|
"scripts": {
|
|
32
34
|
"build": "tsc",
|