Comments (4)
I've published an example here..
The trick is to use ref types for the properties that makes the subtree of your Store.
https://raw.githubusercontent.com/alexdrone/Store/master/Tests/StoreTests/RootStore.swift
from store.
I've released a new version with makeChildStore
(ref types are no more required).
from store.
struct Root {
struct Todo {
var name: String = "Untitled"
var description: String = "N/A"
var done: Bool = false
}
struct Note {
var author: String = "Nobody"
var text: String = ""
var upvotes: Int = 0
}
var todo: Todo = Todo()
var note: Note = Note()
}
class RootStore: Store<Root> {
lazy var todoStore = makeChildStore(keyPath: \.todo)
lazy var noteStore = makeChildStore(keyPath: \.note)
}
extension Root.Todo {
struct Action_MarkAsDone: ActionProtocol {
func reduce(context: TransactionContext<Store<Root.Todo>, Self>) {
defer { context.fulfill() }
context.reduceModel { $0.done = true }
}
}
}
extension Root.Note {
struct Action_IncreaseUpvotes: ActionProtocol {
func reduce(context: TransactionContext<Store<Root.Note>, Self>) {
defer { context.fulfill() }
context.reduceModel { $0.upvotes += 1 }
}
}
}
from store.
Thanks for the release! That’s great!
from store.
Related Issues (18)
- CocoaPods HOT 1
- Tag problem HOT 5
- type 'CounterAction' does not conform to protocol 'ActionType' HOT 2
- Is it okay to use a class instead of a struct for a store? HOT 3
- Add CI Integration? HOT 1
- Installation Section HOT 7
- Potential race condition in Store.run (?) HOT 1
- Type 'CounterAction' does not conform to protocol 'ActionProtocol' HOT 1
- Handling child stores for lists of data HOT 1
- [Question] Async action with combine HOT 5
- iOS 14 compatibility issues HOT 4
- Build failure around RecorderMiddleware+.swift
- Support lower minimal deployment target (current is iOS 10.1) HOT 1
- Compilation error in RecorderMiddleware.swift HOT 5
- Carthage update error (has no shared schemes)
- Build failed with Carthage
- Swift 4 Support
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 store.