Forked from danielmahal/firebase-decorator-api.jsx
Last active
December 16, 2015 09:04
-
-
Save simenbrekken/32c6dea712d83e3c0b91 to your computer and use it in GitHub Desktop.
Firebase decorator api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Alternative 1 | |
// One function at top-level that returns whatever it needs. | |
// Can be run multiple times, and return different things | |
@firebase(props => { | |
if (!props.projectIndex) { | |
return { | |
projectIndex: `users/${props.authId}/projects`, | |
}; | |
} | |
return { | |
projects: mapValues(props.projectIndex, (meta, projectId) => { | |
return `/projects/${projectId}/name`; | |
}), | |
} | |
}) | |
// Alternative 2 | |
// Array with “steps” | |
@firebase({ | |
projects: [ | |
props => `users/${props.authId}/projects`, | |
props => mapValues(projects, (meta, projectId) => { | |
return `/projects/${projectId}/name`; | |
}), | |
] | |
}) | |
// Alternative 3 | |
// Multiple with function that returns an object of paths | |
@firebase({ | |
projects: props => `users/${props.authId}/projects`, | |
}) | |
@firebase({ | |
projects: props => mapValues(projects, (meta, projectId) => { | |
return `/projects/${projectId}/name`; | |
}), | |
}) | |
// Alternative 3 nice-to-have | |
@firebase({ | |
projects: ({projects}) => (meta, projectId) => `/projects/${projectId}/name`, | |
}) | |
// Alternative 4 | |
// One subscription per decorator | |
@firebase('projects', props => `users/${props.authId}/projects`) | |
@firebase('projects', props => mapValues(projects, (meta, projectId) => { | |
return `/projects/${projectId}/name`; | |
})) |
danielmahal
commented
Dec 16, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment