firefly-compiler 0.6.18 → 0.6.19
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/lux/Lux.ff +42 -30
- package/package.json +1 -1
- package/vscode/package.json +1 -1
package/lux/Lux.ff
CHANGED
|
@@ -32,12 +32,12 @@ class LuxDocument(document: JsValue)
|
|
|
32
32
|
data LuxInvaldNameException(name: String)
|
|
33
33
|
|
|
34
34
|
capability LuxEffect[I, O](
|
|
35
|
-
reload: I => Unit,
|
|
36
|
-
cancel: () => Unit,
|
|
37
|
-
result: Option[O],
|
|
38
|
-
loading: Bool,
|
|
39
|
-
error: Bool,
|
|
40
|
-
internalInput: Option[I]
|
|
35
|
+
mutable reload: I => Unit,
|
|
36
|
+
mutable cancel: () => Unit,
|
|
37
|
+
mutable result: Option[O],
|
|
38
|
+
mutable loading: Bool,
|
|
39
|
+
mutable error: Bool,
|
|
40
|
+
mutable internalInput: Option[I]
|
|
41
41
|
)
|
|
42
42
|
|
|
43
43
|
extend self[I: Equal, O]: LuxEffect[I, O] {
|
|
@@ -408,34 +408,46 @@ extend self: Lux {
|
|
|
408
408
|
}
|
|
409
409
|
|
|
410
410
|
useEffect[I, O](effect: I => O, body: LuxEffect[I, O] => Unit) {
|
|
411
|
+
self.useState(False): flip, setFlip =>
|
|
412
|
+
self.useCallback1 {_ => setFlip(!flip)}: update =>
|
|
411
413
|
self.useHook: hook =>
|
|
412
|
-
if(!hook.dry() &&
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
414
|
+
let luxEffect = if(!hook.dry() && hook.hasValue()) {
|
|
415
|
+
hook.grabValue()
|
|
416
|
+
} else {
|
|
417
|
+
let luxEffect = LuxEffect({_ => }, {}, None, False, False, None)
|
|
418
|
+
luxEffect.cancel = {
|
|
419
|
+
luxEffect.loading = False
|
|
420
|
+
luxEffect.error = False
|
|
421
|
+
if(!hook.dry()):
|
|
422
|
+
hook.cleanup()
|
|
423
|
+
update(Unit)
|
|
424
|
+
}
|
|
425
|
+
luxEffect.reload = {input =>
|
|
426
|
+
luxEffect.loading = True
|
|
427
|
+
luxEffect.error = False
|
|
428
|
+
luxEffect.internalInput = Some(input)
|
|
429
|
+
if(!hook.dry()):
|
|
430
|
+
hook.cleanup()
|
|
431
|
+
update(Unit)
|
|
432
|
+
let subtask = hook.luxCopy.task.spawn {task =>
|
|
433
|
+
try {
|
|
434
|
+
let newResult = effect(input)
|
|
435
|
+
luxEffect.loading = False
|
|
436
|
+
luxEffect.error = False
|
|
437
|
+
luxEffect.result = Some(newResult)
|
|
438
|
+
update(Unit)
|
|
439
|
+
} catchAny {error =>
|
|
440
|
+
luxEffect.loading = False
|
|
441
|
+
luxEffect.error = error.name() != "AbortError"
|
|
442
|
+
update(Unit)
|
|
432
443
|
}
|
|
433
444
|
}
|
|
445
|
+
hook.setCleanup {subtask.abort()}
|
|
434
446
|
}
|
|
435
|
-
hook.
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
body(
|
|
447
|
+
if(!hook.dry()) {hook.setValue(luxEffect)}
|
|
448
|
+
luxEffect
|
|
449
|
+
}
|
|
450
|
+
body(luxEffect)
|
|
439
451
|
}
|
|
440
452
|
|
|
441
453
|
useWebSocket(
|
package/package.json
CHANGED