How to use normalizr - 10 common examples

To help you get started, we’ve selected a few normalizr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / normalizr / normalizr-tests.ts View on Github external
response = normalize(response, {
            articles: arrayOf(article1)
        });
    }
}

// new Schema(key, [options])

const article2 = new Schema('articles');

// You can use a custom id attribute
const article3 = new Schema('articles', { idAttribute: 'slug' });

// Or you can specify a function to infer it
function generateSlug(entity: any) { /* ... */ }
const article4 = new Schema('articles', { idAttribute: generateSlug });

// Schema.prototype.define(nestedSchema)

const article5 = new Schema('articles');
const user5 = new Schema('users');

article5.define({
    author: user5
});

// Schema.prototype.getKey()

const article6 = new Schema('articles');

article6.getKey();
// articles
github DefinitelyTyped / DefinitelyTyped / normalizr / normalizr-tests.ts View on Github external
};

// You can specify the name of the attribute that determines the schema
article9.define({
    assets: arrayOf(asset9, { schemaAttribute: 'type' })
});

// Or you can specify a function to infer it
function inferSchema9(entity: any) { /* ... */ }
article9.define({
    assets: arrayOf(asset9, { schemaAttribute: inferSchema9 })
});

// valuesOf(schema, [options])

const article10 = new Schema('articles');
const user10 = new Schema('users');

article10.define({
    collaboratorsByRole: valuesOf(user10)
});

const article11 = new Schema('articles');
const user11 = new Schema('users');
const group11 = new Schema('groups');
const collaborator11 = {
    users: user11,
    groups: group11
};

// You can specify the name of the attribute that determines the schema
article11.define({
github DefinitelyTyped / DefinitelyTyped / normalizr / normalizr-tests.ts View on Github external
//     users: {
        //       7: { ... },
        //       ..
        //     }
        //   }
        // }

        response = normalize(response, {
            articles: arrayOf(article1)
        });
    }
}

// new Schema(key, [options])

const article2 = new Schema('articles');

// You can use a custom id attribute
const article3 = new Schema('articles', { idAttribute: 'slug' });

// Or you can specify a function to infer it
function generateSlug(entity: any) { /* ... */ }
const article4 = new Schema('articles', { idAttribute: generateSlug });

// Schema.prototype.define(nestedSchema)

const article5 = new Schema('articles');
const user5 = new Schema('users');

article5.define({
    author: user5
});
github DefinitelyTyped / DefinitelyTyped / normalizr / normalizr-tests.ts View on Github external
//     }
        //   }
        // }

        response = normalize(response, {
            articles: arrayOf(article1)
        });
    }
}

// new Schema(key, [options])

const article2 = new Schema('articles');

// You can use a custom id attribute
const article3 = new Schema('articles', { idAttribute: 'slug' });

// Or you can specify a function to infer it
function generateSlug(entity: any) { /* ... */ }
const article4 = new Schema('articles', { idAttribute: generateSlug });

// Schema.prototype.define(nestedSchema)

const article5 = new Schema('articles');
const user5 = new Schema('users');

article5.define({
    author: user5
});

// Schema.prototype.getKey()
github DefinitelyTyped / DefinitelyTyped / normalizr / normalizr-tests.ts View on Github external
group12.define({
    creator: unionOf(member12, { schemaAttribute: inferSchema })
});

const group13 = new Schema('groups');
const user13 = new Schema('users');

const member13 = unionOf({
    users: user13,
    groups: group13
}, { schemaAttribute: 'type' });

group13.define({
    owner: member13,
    members: arrayOf(member13),
    relationships: valuesOf(member13)
});

// normalize(obj, schema, [options])

const article14 = new Schema('articles');
const user14 = new Schema('users');

article14.define({
    author: user14,
    contributors: arrayOf(user14),
    meta: {
        likes: arrayOf({
            user: user14
        })
    }
});
github DefinitelyTyped / DefinitelyTyped / normalizr / normalizr-tests.ts View on Github external
const user11 = new Schema('users');
const group11 = new Schema('groups');
const collaborator11 = {
    users: user11,
    groups: group11
};

// You can specify the name of the attribute that determines the schema
article11.define({
    collaboratorsByRole: valuesOf(collaborator11, { schemaAttribute: 'type' })
});

// Or you can specify a function to infer it
function inferSchema11(entity: any) { /* ... */ }
article11.define({
    collaboratorsByRole: valuesOf(collaborator11, { schemaAttribute: inferSchema })
});

// unionOf(schemaMap, [options])

const group12 = new Schema('groups');
const user12 = new Schema('users');

// a member can be either a user or a group
const member12 = {
    users: user12,
    groups: group12
};

// You can specify the name of the attribute that determines the schema
group12.define({
    owner: unionOf(member12, { schemaAttribute: 'type' })
github DefinitelyTyped / DefinitelyTyped / normalizr / normalizr-tests.ts View on Github external
assets: arrayOf(asset9, { schemaAttribute: 'type' })
});

// Or you can specify a function to infer it
function inferSchema9(entity: any) { /* ... */ }
article9.define({
    assets: arrayOf(asset9, { schemaAttribute: inferSchema9 })
});

// valuesOf(schema, [options])

const article10 = new Schema('articles');
const user10 = new Schema('users');

article10.define({
    collaboratorsByRole: valuesOf(user10)
});

const article11 = new Schema('articles');
const user11 = new Schema('users');
const group11 = new Schema('groups');
const collaborator11 = {
    users: user11,
    groups: group11
};

// You can specify the name of the attribute that determines the schema
article11.define({
    collaboratorsByRole: valuesOf(collaborator11, { schemaAttribute: 'type' })
});

// Or you can specify a function to infer it
github flow-typed / flow-typed / definitions / npm / normalizr_v2.x.x / test_normalizr-v2.js View on Github external
// @flow
import Normalizr from 'normalizr';

(Normalizr.normalize({ foo: '' }, {}): Object);
(Normalizr.normalize([{ foo: '' }], {}): Object);
(Normalizr.valuesOf({}): Normalizr$Schema);
// $ExpectError
(Normalizr.normalize(): Object);
github DefinitelyTyped / DefinitelyTyped / normalizr / normalizr-tests.ts View on Github external
// You can specify the name of the attribute that determines the schema
group12.define({
    owner: unionOf(member12, { schemaAttribute: 'type' })
});

// Or you can specify a function to infer it
function inferSchema(entity: any) { /* ... */ }
group12.define({
    creator: unionOf(member12, { schemaAttribute: inferSchema })
});

const group13 = new Schema('groups');
const user13 = new Schema('users');

const member13 = unionOf({
    users: user13,
    groups: group13
}, { schemaAttribute: 'type' });

group13.define({
    owner: member13,
    members: arrayOf(member13),
    relationships: valuesOf(member13)
});

// normalize(obj, schema, [options])

const article14 = new Schema('articles');
const user14 = new Schema('users');

article14.define({
github DefinitelyTyped / DefinitelyTyped / normalizr / normalizr-tests.ts View on Github external
// a member can be either a user or a group
const member12 = {
    users: user12,
    groups: group12
};

// You can specify the name of the attribute that determines the schema
group12.define({
    owner: unionOf(member12, { schemaAttribute: 'type' })
});

// Or you can specify a function to infer it
function inferSchema(entity: any) { /* ... */ }
group12.define({
    creator: unionOf(member12, { schemaAttribute: inferSchema })
});

const group13 = new Schema('groups');
const user13 = new Schema('users');

const member13 = unionOf({
    users: user13,
    groups: group13
}, { schemaAttribute: 'type' });

group13.define({
    owner: member13,
    members: arrayOf(member13),
    relationships: valuesOf(member13)
});