Skip to content

Instantly share code, notes, and snippets.

@krainboltgreene
Created May 19, 2018 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krainboltgreene/4a63dcedae4ce53fbc7a3e0c0eb8449b to your computer and use it in GitHub Desktop.
Save krainboltgreene/4a63dcedae4ce53fbc7a3e0c0eb8449b to your computer and use it in GitHub Desktop.
// KeyChain:: Array<mixed>
// Before:: mixed
// After:: Mixed
// Replacements:: Map<Before, After>
// patchTree:: (Map<KeyChain, Replacements>) => Object => Object
export default patchTree(
new Map([
[
["id"],
["me", current_account.id],
],
[
["data", "id"],
new Map([
["me", current_account.id],
]),
],
[
["data", "relationships", "billing-information", "data", "id"],
new Map([
["latest", current_account.billing_informations.last.id],
["current", current_cart.billing_information.id],
]),
],
])
)
import shortcutReplacement from "patchtree-2"
shortcutReplacement({
id: "me",
data: {
attributes: {
name: "Kurtis Rainbolt-Greene"
},
relationships: {
"billing-informations": {
data: {
id: "current"
}
}
}
}
})
{
id: "1",
data: {
attributes: {
name: "Kurtis Rainbolt-Greene"
},
relationships: {
"billing-informations": {
data: {
id: "2"
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment