@@ -170,68 +170,79 @@ updateModel SyncInputs st = do
170
170
syncInputs st
171
171
pure Noop
172
172
]
173
- updateModel (ChanUpdate f) st = do
174
- let prevSt = f st
173
+ updateModel (ChanUpdate update0) st0 = do
174
+ let st1 = update0 st0
175
175
batchEff
176
- prevSt
176
+ st1
177
177
[ do
178
178
--
179
179
-- NOTE : Workaround to fix slow rendering after screen switch.
180
180
--
181
181
sleepMilliSeconds 300
182
- pure SyncInputs
183
- -- do
184
- -- actions <-
185
- -- drainTChan $ prevSt ^. #modelConsumerQueue
186
- -- nextSt <-
187
- -- handleAny
188
- -- ( \e -> do
189
- -- consoleLog e
190
- -- pure $ prevSt & #modelLoading .~ False
191
- -- )
192
- -- $ evalModel
193
- -- =<< foldlM evalUpdate prevSt actions
194
- -- uri <- stUri nextSt
195
- -- Jsm.insertStorage ("favorite-" <> vsn) (nextSt ^. #modelFavMap)
196
- -- Jsm.insertStorage ("current-" <> vsn) uri
197
- -- syncUri uri
198
- -- nextUri <- stUri $ nextSt & #modelState . #stScreen %~ unQrCode
199
- -- uriViewer <-
200
- -- newFieldPair mempty
201
- -- . DynamicFieldText
202
- -- . from @Prelude.String @Unicode
203
- -- $ URI.renderStr nextUri
204
- -- let finSt =
205
- -- nextSt
206
- -- & #modelUriViewer
207
- -- %~ mergeFieldPairs
208
- -- [ uriViewer
209
- -- & #fieldPairValue
210
- -- . #fieldOpts
211
- -- . #fieldOptsQrState
212
- -- .~ Just Opened
213
- -- ]
214
- -- if finSt ^. #modelLoading
215
- -- then do
216
- -- void
217
- -- . spawnLink
218
- -- . deepseq (viewModel finSt)
219
- -- . pushActionQueue prevSt
220
- -- . Instant
221
- -- . PureUpdate
222
- -- . const
223
- -- $ finSt
224
- -- & #modelLoading
225
- -- .~ False
226
- -- pure
227
- -- . ChanUpdate
228
- -- $ #modelLoading
229
- -- .~ True
230
- -- else
231
- -- pure
232
- -- . ChanUpdate
233
- -- $ #modelLoading
234
- -- .~ False
182
+ pure SyncInputs ,
183
+ do
184
+ actions <-
185
+ drainTChan $ st1 ^. # modelConsumerQueue
186
+ update1 <-
187
+ foldlM
188
+ ( \ acc upd -> do
189
+ fun <- unUpdate upd
190
+ pure $ fun . acc
191
+ )
192
+ id
193
+ actions
194
+ let st2 = update1 st1
195
+ update2 <-
196
+ handleAny
197
+ ( \ e -> do
198
+ consoleLog e
199
+ pure $ # modelLoading .~ False
200
+ )
201
+ $ evalModel st2
202
+ let st3 = update2 st2
203
+ uri <- stUri st3
204
+ Jsm. insertStorage (" favorite-" <> vsn) $ st3 ^. # modelFavMap
205
+ Jsm. insertStorage (" current-" <> vsn) uri
206
+ syncUri uri
207
+ nextUri <- stUri $ st3 & # modelState . # stScreen %~ unQrCode
208
+ uriViewer <-
209
+ newFieldPair mempty
210
+ . DynamicFieldText
211
+ . from @ Prelude. String @ Unicode
212
+ $ URI. renderStr nextUri
213
+ let update3 =
214
+ # modelUriViewer
215
+ %~ mergeFieldPairs
216
+ [ uriViewer
217
+ & # fieldPairValue
218
+ . # fieldOpts
219
+ . # fieldOptsQrState
220
+ .~ Just Opened
221
+ ]
222
+ let st4 = update3 st3
223
+ if st4 ^. # modelLoading
224
+ then do
225
+ void
226
+ . spawnLink
227
+ . deepseq (viewModel st4)
228
+ . pushActionQueue st4
229
+ . Instant
230
+ . PureUpdate
231
+ $ # modelLoading
232
+ .~ False
233
+ pure
234
+ . ChanUpdate
235
+ $ (# modelLoading .~ True )
236
+ . update3
237
+ . update2
238
+ . update1
239
+ else
240
+ pure
241
+ . ChanUpdate
242
+ $ (# modelLoading .~ False )
243
+ . update3
244
+ . update2
245
+ . update1
235
246
]
236
247
updateModel (PushUpdate value) st = do
237
248
case instantOrDelayedValue value of
0 commit comments