Skip to content

v1.0.2

Compare
Choose a tag to compare
@puppybits puppybits released this 16 Jul 19:14
· 41 commits to master since this release

v1.0.2 - Turn on Immediate Mode for the UI

  • Cache Reducer. UI feels instantaneous to users.
    • Enables optimistic updates for new, deleted & updated data.
    • All data changes synchronously reflected in the redux state cache reducer queries.
    • Once Firestore approves/rejects a change it also removes the optimistic commit.
// selector for cache reducer
(state) => state.firebase.firestore.cache[myStoreAs].docs;

// access read-only fragment of Firestore based on all active queries
const document = state.firebase.firestore.cache.database[full_path_to_collection][document_id];
  • Mutate. Simplifies saving, batching and transactions.
    • Easily switch between single saves and atomic transactions.
    • Simplifies complex saves that have to coordinate through multiple actions.
    • Synchronously updates queries in the cache reducer for instance UI feedback for the app.
// single save
getFirestore().mutate({collection: 'tasks', doc: 'task-1', data: {status: 2}});

// batch
getFirestore().mutate([
  {collection: 'tasks', doc: 'task-1', data: {status: 2}},
  {collection: 'tasks', doc: 'task-2', data: {status: 2}},
]);

// transaction, 'reads' firestore docs or provide local variables to dependency injection for 'writes' functions.
getFirestore().mutate({
  reads: { 
    uid: () => 'my-user-id',
    task1: { collection: 'tasks', doc: 'task-1' } 
  },
  writes: [ 
    ({ uid, task1 }) => ({
        collection: 'tasks', 
        doc: task1.id, 
        data: { status: task1.status +1, updatedBy: uid }
     }) 
   ]
});