Skip to content

create requires 'path' 2x? #6

@brandonmp

Description

@brandonmp

using the create saga & wondering about the source code here (which is also the same source code for push?):

/**
 * Saves new data to the database with `set()`
 *
 * @param path
 * @param fn
 * @example
 * import { create } from 'firebase-saga';
 *
 * yield call(create, 'posts', () => ({
 *              [`posts/1234`]: {
 *                   title: 'My Second Post',
 *                   body: 'Second post details',
 *                   timestamp: +new Date
 *               }
 *           })
 *);
 */
export function* create(path, fn) {
    const key = yield call(newKey, path);
    const payload = yield call(fn, key);
    const opts = newOpts('error');
    const ref = firebase.database().ref();
    const [_, { error }] = yield [
        call([ref, ref.update], payload, opts.handler),
        take(opts)
    ];
    return error;
}

Why does the API require declaring 'posts' as the 2nd arg, and 'posts' in the prop name of the anon set function?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions