prescottprue/redux-firestore
关于
Redux 与 Firestore 的绑定
开发工具实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文redux-firestore
Redux bindings for Firestore. Provides low-level API used in other libraries such as react-redux-firebase
Installation
npm install redux-firestore --save
This assumes you are using npm as your package manager.
If you're not, you can access the library on unpkg, download it, or point your package manager to it. Theres more on this in the Builds section below
Complementary Package
Most likely, you'll want react bindings, for that you will need react-redux-firebase. You can install the current version it by running:
npm install --save react-redux-firebase
react-redux-firebase provides withFirestore and firestoreConnect higher order components, which handle automatically calling redux-firestore internally based on component's lifecycle (i.e. mounting/un-mounting)
Overview
- Getting Started
- API
API Quick Start
Load data
Construct a Firestore query, attach listeners for updates and get the data from the selector.
const MyController = () => {
// 1. construct query
const taskQuery = {
collection: `workspace/MySpace/tasks`,
where:[
['status', '<', 1],
['deleted', '==', false]
],
orderBy: ['createdAt', 'desc'],
storeAs: 'tasksStarted',
}
// 2. load & attached listeners for document changes
useFirestoreConnect([taskQuery]);
// 3. Get results
const tasks = useSelector(state =>
state.firestore.cache['tasksStarted'].docs
);
// 4. Display when the data returns
return (<ol>
{tasks && tasks.map(({id, title}) => (
<li key={id}>title</li>
))}
</ol>);
};
Saving Data
Use redux-firestore's mutate function to queue changes to Firestore and see the optimitic results instantly in the UI.
const MyController = (task) => {
const changeTitle = useCallback(({id, path, title}) => {
dispatch(
createMutate({
doc: id,
collection: path,
title
}))
.catch((error) => { alert(error) });
})
return (<TaskView onSave={changeTitle} />);
};
Roadmap
- Automatic support for documents that have a parameter and a subcollection with the same name (currently requires
storeAs) - Support for Passing a Ref to
setListenerin place ofqueryConfigobject or string
Post an issue with a feature suggestion if you have any ideas!
探索相关项目
加载中…