This file contains hidden or 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
update('lists', { | |
favoriteBooks: [2, 50, 22] | |
}, { | |
resourceType: 'books' | |
}); | |
update('resources', [2, 50, 10], { | |
defaultData: { | |
resourceType: 'books', | |
meta: { |
This file contains hidden or 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
// Originally, it was like this | |
{ | |
resources: { | |
books: { | |
// This shit is secret, and should not be exposed to the users. | |
__internalInfoAboutBooks: {}, | |
resources: { | |
24: { ... }, |
This file contains hidden or 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
getResources('books', { | |
filter: { | |
firstName: 'javi' | |
} | |
}); | |
getResources('books', { | |
filter: resource => resource.meta.isSelected | |
}); |
This file contains hidden or 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
// Deep merge | |
update('resources.books', { | |
24: { | |
attributes: { | |
firstName: 'james' | |
} | |
} | |
}); | |
// Do some shit |
This file contains hidden or 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
// The "metadata" layer – the first layer after the resourceType or | |
// list name, is "skipped" in the pathing syntax, as users are not able | |
// to modify the store at that layer. | |
{ | |
resources: { | |
books: { | |
resources: { | |
24: { ... }, | |
50: { ... } |
This file contains hidden or 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
{ | |
id, | |
resourceType, | |
attributes, | |
meta, | |
computedAttributes | |
} |
This file contains hidden or 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
// Given a flat resource and its schema, returns a full resource. | |
export default function fullFromFlat({ resource, schema }) { | |
const attributes = Object.values(schema.attributes); | |
const metas = Object.values(schema.meta); | |
const newAttributes = {}; | |
attributes.map(attribute => { | |
if (resource[attribute]) { | |
newAttributes[attribute] = resource[attribute]; | |
} |
This file contains hidden or 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
{ | |
// These are the resource types in this relationship. | |
// In this case, both sides of the relationship are people. | |
resourceTypes: ['people'], | |
relationshipSchema: { | |
fields: { | |
father: { | |
resourceType: 'people', | |
}, |
This file contains hidden or 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
export default function isEqual(x, y) { | |
// Handles primitives and exact object matches | |
if (x === y) { | |
return true; | |
} | |
// We can only handle comparing "regular" objects and | |
// arrays; everything else is considered not equal. | |
else if ( | |
((x && x.constructor === Object) || Array.isArray(x)) && |
This file contains hidden or 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
update({ | |
books: { | |
24: { | |
name: 'Lord of the Rings' | |
} | |
} | |
}); | |
update('books', { | |
24: { |