Comments (5)
Yes, that's intended behaviour so far. You're creating a new Signal of type Void that uses the convenience init. This init now stores the last result (a successful result of void) and every subscriber get's the last result on subscription. Then on update you run the whole chain again - resulting in the second next fired.
Currently I'm using a workaround of using a Signal<Bool>()
and then update that with true (which also calls next on subscribe if it has been fired before). I see how handy a case of a void signal without storage would be for user interaction, but I'm still a bit hesitant to include a if $0 is Void
everywhere in the source code of Signal
. Also it would be a bit strange if a Signal of one type behaves differently to a signal of another type.
Maybe you have an idea for better semantics of void signals?
from interstellar.
No I agree with you. I was just surprised at the behavior.
I wonder if an alternate form of init() might be possible. I'll play around and see what i can come up with.
from interstellar.
Why does Signal
send the last value on subscription? Could we have at least a choice to send only send values on update
? I guess that's veering towards the hot & cold semantics...
from interstellar.
Yep, it is. If you think about a UITextField
having a textSignal: Signal<String>
-property, most of the time it's handy to send the last value on subscribe to e.g. update a label. But this has several drawbacks: possible memory leaks, sending void
on subscribe, breaking the first run of Thread
-calls or just unexpected behaviour (like sending something when subscribing to a button). Therefore I'm not overly happy with the current implementation.
I have two ideas how to deal with this:
- removing the
value
-property, soSignal
becomes stateless (getting rid of the state also removes our last dependency on Foundation to sync the access onupdate
) - adding an option to
subscribe
that defaults to false (this would correspond to key-value-observing'sNSKeyValueObservingOptionInitial
-option)
What do you think?
from interstellar.
V2 now allows for Observable<Void>
.
from interstellar.
Related Issues (20)
- Signal could be struct HOT 2
- Adding Signal update(f: T? -> T) HOT 5
- Interstellar 2.0 HOT 18
- Debounce using GCD? HOT 1
- Yosemite support HOT 5
- Memory leak when map'ing signals HOT 4
- More complex unsubscription in v2 HOT 5
- Possible data race in function `subscribe`
- Not sure about how `debounce` works HOT 2
- Swift 3 version HOT 2
- Missing comma in .podspec file
- Question regarding Thread class HOT 2
- global(qos:) only available on OSX 10.10 HOT 1
- Debounce doesn't deliver last call to update
- Feature Request: API for cancelling underlying async task HOT 5
- Using Queue with observable, maybe race condition? HOT 1
- Filter HOT 3
- Updating observable's value without triggering update HOT 1
- Zero-Knowledge Disposal HOT 5
- Swift's 5 Result type HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from interstellar.