阅读商店在Redux Reducer中的初始状态(Read Store's Initial State in Redux Reducer)
Redux应用程序中的初始状态可以通过两种方式设置:
- 作为第二个参数传递给
createStore
( docs link )- 作为您的(子)reducers( docs链接 )的第一个参数传递它
如果您将初始状态传递到您的商店,那么您如何从商店中读取该状态,并将其作为reducer中的第一个参数?
Initial state in a Redux app can be set in two ways:
- pass it as the second argument to
createStore
(docs link)- pass it as the first argument to your (sub-)reducers (docs link)
If you pass initial state to your store, how do you read that state from the store and make it the first argument in your reducers?
原文:https://stackoverflow.com/questions/33749759
最满意答案
你需要附加一个观察者的值。
ref.observe(FIRDataEventType.value, with: { (snapshot) in AppVersionLabel.text = snapshot.value as? String? })
如果您只对当前版本号感兴趣(而不是自动接收更新),则可以使用具有相同签名的
observeSingleEvent
。请参阅https://firebase.google.com/docs/database/ios/read-and-write#listen_for_value_events
You need to attach an observer for the value.
ref.observe(FIRDataEventType.value, with: { (snapshot) in AppVersionLabel.text = snapshot.value as? String? })
If you're only interested in the current version number (and not in receiving updates automatically), you can use
observeSingleEvent
with the same signature.See https://firebase.google.com/docs/database/ios/read-and-write#listen_for_value_events
相关问答
更多-
你需要附加一个观察者的值。 ref.observe(FIRDataEventType.value, with: { (snapshot) in AppVersionLabel.text = snapshot.value as? String? }) 如果您只对当前版本号感兴趣(而不是自动接收更新),则可以使用具有相同签名的observeSingleEvent 。 请参阅https://firebase.google.com/docs/database/ios/read-and-write#listen ...
-
我想到了 let database = FIRDatabase.database().reference() database.child("Users").observeSingleEvent(of: FIRDataEventType.value, with: { (snapshot) in print(snapshot) if snapshot.hasChild( FIRAuth.auth()!.currentUser!.uid) { ...
-
我已经给出了一个示例函数来更新firebase中的投票计数值。 尝试以下操作 func adddComment() { dataBaseRef.child("MemesBilder").child(userId).child("anzahlKommentare").runTransactionBlock({ (currentData: FIRMutableData) -> FIRTransactionResult in var voteCount = currentData.value as? ...
-
Firebase搭配Swift(Firebase with Swift)[2022-04-02]
我设法让它运作起来。 事实证明,firebase网站上的视频解释了哪些依赖项已经过时了。 我在页面下面进一步阅读,看到firebase实际上需要两个我缺少的依赖项。 添加libc++.dylib , libiucore.dylib , CFNetwork.framework , Security.framework和SystemConfiguration.framework一切正常。 I managed to get it working. It turns out that the video on th ... -
我猜你没有将你检索到的Snapshot从一个事件转换成任何类型,这可能导致Xcode对这个Snapshot甚至属于哪种类型感到困惑? FIRDatabase.database().reference().observeSingleEvent(of : .value, with : {(Snapshot) in if let snapDict = Snapshot.value as? [String:AnyObject]{ for child in snapDi ...
-
firebase查询和swift(firebase queries and swift)[2022-09-08]
不幸的是,Firebase不支持通过这样的内容进行搜索(在任何语言SDK中)。 来自2016年7月的Google网上论坛帖子 : 作为一家了解搜索的公司,我们也是一家了解使用最佳工具的公司。 对于模糊匹配和包含,NoSQL,实时数据存储不是正确的工具 - 这些查询会很慢并且扩展性很差。 BigQuery或ElasticSearch是以可扩展和健壮的方式提供有用结果的正确工具。 现在,这涉及部署一个小节点脚本来将搜索结果与实时数据同步,如使用示例Flashlight库的文章中所述。 随着我们在Firebase ... -
好吧,看起来这是因为我的本地和云版本的数据不同步,因此测试期间的结果不一致(我必须运行测试,用旧备份替换测试后数据,重复)I通过将此行添加到我的初始化代码来修复这些问题: ref?.child("play-data").keepSynced(true) 我之前已经有过这个: db?.persistenceEnabled = true 其中ref和db是对FIRDatabaseReference / FIRDatabase的引用。 OK, looks like this was the result of ...
-
我认为你的查询是正确的,你忘记了观察者: FIRDatabase.database().reference() .child("groups").queryOrdered(byChild: "users/" + uid).queryEqual(toValue: writable).observe(FIRDataEventType.value, with: { (snapshot) in // Do what you need with your snapshot here // chec ...
-
Firebase:如何从子节点swift提取子键值(Firebase: how to extract child key value from child node swift)[2021-12-01]
尝试这个:- 斯威夫特3 FIRDatabase.database().reference().child("Followers").child(FIRAuth.auth()!.currentUser!.uid).observeSingleEvent(of: .value, with: { (snapshot) in if let userDict = snapshot.value as? [String:AnyObject]{ for each in userDic ... -
你只需要打开你收到的价值: - FIRDatabase.database().reference().child("Ring1Fighting").observe(.value) { (snap: FIRDataSnapshot) in print((snap.value as! String)) } You just need to unwrap the value that you recieve:- FIRDatabase.database().reference(). ...