Last active
July 3, 2016 12:37
-
-
Save itsmepetrov/1bcc35d10c970a1af196576b91622f30 to your computer and use it in GitHub Desktop.
Normalize deep nested query with normalizr
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
import { Schema, arrayOf, normalize } from "normalizr" | |
const input = { | |
id: 100, | |
title: 'Playing with normalizr', | |
text: 'Normalize deep nested query with normalizr', | |
likes: { | |
total: 1, | |
page: 1, | |
limit: 10, | |
users: [{ | |
id: 1, | |
name: 'Anton Petrov' | |
}] | |
} | |
} | |
var user = new Schema('users') | |
var post = new Schema('posts') | |
post.define({ | |
likes: { | |
users: arrayOf(user) | |
} | |
}) | |
const result = normalize(input, post) | |
console.log(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment