Skip to content

Commit 0edfcf7

Browse files
committed
fix: switch to array from map
1 parent aefabcd commit 0edfcf7

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

src/index.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,15 @@ const normalize = <T extends Settings>(
209209
}))
210210

211211
interface LocalState<T extends Settings> {
212-
records: Map<number | string | symbol, Required<Plugin<Types<T>, T>>>
212+
records: Array<Required<Plugin<Types<T>, T>>>
213213
initialState: {}
214214
state: {}
215215
log: Action[]
216216
}
217217

218218
class Lens<T extends Settings> {
219219
private readonly state: LocalState<T> = {
220-
records: new Map(),
220+
records: [],
221221
initialState: {},
222222
state: {},
223223
log: []
@@ -309,26 +309,22 @@ class Lens<T extends Settings> {
309309

310310
this.state.initialState = Object.assign(
311311
{},
312-
...Array.from(this.state.records.values()).map(
313-
record => record[Options.InitialState]
314-
)
312+
...this.state.records.map(record => record[Options.InitialState])
315313
)
316314
}
317315

318316
private setState() {
319317
this.state.state = Object.assign(
320318
{},
321319
this.state.initialState,
322-
...Array.from(this.state.records.values()).map(record =>
320+
...this.state.records.map(record =>
323321
record[Options.Reducer](this.state.log)
324322
)
325323
)
326324
}
327325

328-
private interfaces(): {} {
329-
const keys: (string | number | symbol)[] = []
330-
331-
this.state.records.forEach(record => {
326+
private disabled(): Array<Required<Plugin<Types<T>, T>>> {
327+
return this.state.records.filter(record => {
332328
const once = record[Options.Once]
333329
? !some(this.state.log, action => action.type === record[Options.Type])
334330
: true
@@ -343,17 +339,27 @@ class Lens<T extends Settings> {
343339
some(this.state.log, action => action.type === type)
344340
)
345341

346-
if (!(enabled && conflicts && dependencies && once)) {
347-
record[Options.Keys].forEach(key => keys.push(key))
348-
}
342+
return !(enabled && conflicts && dependencies && once)
349343
})
344+
}
345+
346+
// private enabled(): Array<Required<Plugin<Types<T>, T>>> {
347+
// return this.state.records.filter(record =>
348+
// this.disabled().indexOf(record) === -1
349+
// )
350+
// }
351+
352+
private interfaces(): {} {
353+
const keys: (string | number | symbol)[] = this.disabled().flatMap(
354+
record => record[Options.Keys]
355+
)
350356

351357
const combinedInterfaces = Object.assign(
352358
{
353359
[SYMBOL_LOG]: this.state.log,
354360
[SYMBOL_STATE]: this.state.state
355361
},
356-
...Array.from(this.state.records.values()).map(record =>
362+
...this.state.records.map(record =>
357363
record[Options.Interface](this.dispatch.bind(this), this.state.state)
358364
)
359365
)
@@ -368,7 +374,7 @@ class Lens<T extends Settings> {
368374

369375
private setRecords(records: Required<Plugin<Types<T>, T>>[]) {
370376
records.forEach(record => {
371-
this.state.records.set(record[Options.Type], record)
377+
this.state.records.push(record)
372378
})
373379
}
374380
}

0 commit comments

Comments
 (0)