Open brandonmp opened 8 years ago
@brandonmp Regarding your question around create
and push
, there are slightly different in sense that push
passes path into the firebase reference where create
doesn't.
const ref = firebase.database().ref(path);
Also both create
and push
wrap the consecutive Firebase helpers.
Why does the API require declaring 'posts' as the 2nd arg?
call
that requires the function name as the first argument and followed by the rest of the arguments including path.And 'posts' in the prop name of the anon set function?
create
requires 'path' 2x?
create
the function has posts
as part of its property. But it's up to you how you would like to implement that function. okay, but path
is only used in generating a new key (which a push
operation). shouldn't the signature for the create
saga be create(path, payload)
?
It looks like the current flow goes like this:
fn
function that was passed to create
(which isn't used in the example) why not:
export function* create(path, payload /*obj*/) {
const opts = newOpts('error');
const ref = firebase.database().ref(path);
const [_, { error }] = yield [
call([ref, ref.set], payload, opts.handler),
take(opts)
];
return error;
}
then the signature is simply:
yield call(create, 'path/to/items/item#', payload)
this (a) avoids having to write a function that just returns an object, (b) avoids repeating the path twice, and (c) gives users the option to use set
or update
under the hood (since both operate differently)
using the
create
saga & wondering about the source code here (which is also the same source code for push?):Why does the API require declaring 'posts' as the 2nd arg, and 'posts' in the prop name of the anon set function?