bodil / bodil/purescript-signal

Atomic update

Open
#55 1 comment 3 reactions 0 assignees View on GitHub
enhancement help wanted
Dominant language
PureScript
Stars
260
Forks
41
PR merge metrics
No merged PRs in 30d

Description

Is it possible to implement atomic updates, so that if a signal receives multiple updates from its dependent signals, it will only emit one signal value if these updates are originally from the same signal update?

For example, let's say signal `b` and signal `c` depend on signal `a`, and signal `d` depends on both `b` and `c`. If there is new signal value sent to signal `a`, it should trigger only one signal.
This is the dependency graph:
```
a
/ \
b c
\ /
d
```
As if right now, it triggers twice.

```
main = do
cn <- channel 1
let a = subscribe cn
let b = (_ + 1) <$> a
let c = (_ + 3) <$> a
let d = (+) <$> b <*> c
let ds = (\x -> [x]) <$> d
let all = foldp (<>) [] ds
send cn 100
runSignal (all ~> show >>> log)
```

```
* Build successful.
[204,105,6]
```
^^^^^^^^^^^ Expect to be `[204, 6]`, but got `[204,105,6]`.
204 = (100 + 1) + (100 + 3)
105 = (100 + 1) + (4)
6 = (1 + 1) + (1 + 3)

`105` is an intermediate value that could be ignored if supports atomic updates.

Atomic updates is useful for UI rendering optimization. If a view's rendering depends on multiple signals, and they are all updated by the same signal value from their dependencies, atomic updates can make sure the view will only be rerendered once.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by inspecting the implementation behind subscribe, the signal combinators, and run the provided dependency-graph example. Done means one update to a produces [204, 6] rather than [204,105,6], while preserving the described signal behavior.

Written by the indexing model from the issue text.

Assessment

Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.