reactivecocoa / loop Goto Github PK
View Code? Open in Web Editor NEWComposable unidirectional data flow with ReactiveSwift.
License: Other
Composable unidirectional data flow with ReactiveSwift.
License: Other
Resurrecting old proposal from @inamiy babylonhealth/ReactiveFeedback#41
This is an additive change to add Optional<Event>
argument in Feedback
so that unnecessary intermediate states will no longer be required.
Event-driven feedback will be useful for following scenarios, without needing to add a new state and then transit (and transit back again):
This is a change from Moore model to (kind of) Mealy model as discussed in babylonhealth/ReactiveFeedback#32 (review) .
Please note that reducer
and feedback
are still in sequence, not parallel.
Also, please note that Optional<Event>
is used here as a workaround since it requires more breaking changes to minimize into non-optional Event
.
Loop may offer in-built SwiftUI integration on Apple platforms without creating an extra "LoopUI" package.
Loop only needs to provide standard data funnels to connect feedback loops with SwiftUI, and has no involvement in UI concerns except for the two characters in import SwiftUI
. Everything else is SwiftUI's declarative UI realm (data to virtual DOM, vDOM to native view, etc). That is in contrast to our UIKit sibling ReactiveCocoa, which is a heavy UI-focused library that (1) attempted to solve AppKit/UIKit reactive programming at a micro level (KVO-like property bindings), and (2) wraps parts of Objective-C dynamism into friendly Swift APIs.
Since SwiftUI is shipped with the system, no friction is incurred for dependency management on users' end. All these collectively makes it perfect for Loop to offer straightly the said utilities.
Such integration should be excluded from Linux builds.
Concepts are built upon the implicit behavior of DynamicProperty
, which serves as a clue for SwiftUI runtime to look inside the property wrapper, so as to pick up embedded special wrappers like @State
, @ObservedObject
and @Environment
.
This enables us to build custom property wrappers that provide simple dev experience, while hiding the heavy lifting of bridging feedback loops to SwiftUI world.
@ObservedObject
:typealias WeatherStore = Store<WeatherState, WeatherAction>
struct WeatherView: View {
@WeatherStore.Binding
var state: WeatherState
init(store: WeatherStore) {
_state = store.binding()
}
var body: some Body {
VStack {
Spacer()
Text("Current temperature: \(state.temperature)")
+ Text(" \(state.unit)").font(.system(size: 10.0)).baselineOffset(7.0)
Spacer()
Button()
action: { self.$state.perform(.refresh) }
label: { Text("Refresh ๐") }
Spacer()
}
}
Note: Unlike @State
and @ObservedObject
, it hasn't been tested whether @EnvironmentObject
would work.
typealias WeatherStore = Store<WeatherState, WeatherAction>
struct WeatherView: View {
@WeatherStore.EnvironmentBinding
var state: WeatherStore.State
var body: some Body {
VStack {
Spacer()
Text("Current temperature: \(state.temperature)")
+ Text(" \(state.unit)").font(.system(size: 10.0)).baselineOffset(7.0)
Spacer()
Button()
action: { self.$state.perform(.refresh) }
label: { Text("Refresh ๐") }
Spacer()
}
}
typealias WeatherStore = Store<WeatherState, WeatherAction>
let weatherStore = WeatherStore()
struct ContentView: View {
var body: some Body {
WeatherView()
.environmentObject(weatherStore)
}
}
Already supported via Store.view(value:event:)
. e.g. injecting via @EnvironmentBinding
a partial store that exposes only state & events related to radar images.
typealias WeatherStore = Store<WeatherState, WeatherAction>
let weatherStore = WeatherStore()
struct ContentView: View {
var body: some Body {
RadarView()
.environmentObject(
weatherStore.view
value: \WeatherState.radarImages
event: WeatherAction.radar
)
}
}
At this point I do not see a value having two sightly different implementation of the same thing.
I proposing to remove old system operator that takes scheduler in favour of new queue-drain event processing.
FeedbackLoop.Feedback -> Feedback
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.