Last active
June 7, 2017 19:47
-
-
Save danielmahal/9d140b2929de723b2c59 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(props.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(props.projects, (meta, projectId) => { | |
return `/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`; | |
})) | |
// Alternative 5 | |
// Multiple with function at top-level | |
@firebase(props => ({ | |
projects: `users/${props.authId}/projects`, | |
})) | |
@firebase(props => ({ | |
projects: mapValues(props.projects, (meta, projectId) => { | |
return `/projects/${projectId}/name`; | |
}), | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alternative 5!
Step 1
First we get the index:
This function will simply return and will be used as a subscription model for the decorator
The props for the component will be something like:
Step 2
Then a “second pass” or child component will resolve the project names:
Through
mapValues
, we end up with an object of id/path as the subscription modelThe final props for the component will be something like: