How to use the normalizr.valuesOf function in normalizr

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
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 hackoregon / btc-frontend-2016-ReactRedux / src / client / api / serverApi.js View on Github external
});
const pacContribution = new Schema('pacContributions', {
  idAttribute: 'contributorPayee'
});
const businessContribution = new Schema('businessContributions', {
  idAttribute: 'contributorPayee'
});
const contributions = ({
  owner: campaign,
  individual: arrayOf(indivContribution),
  business: arrayOf(businessContribution),
  pac: arrayOf(pacContribution),
  states: arrayOf(stateContribution)
});
campaign.define({
  listByName: valuesOf(campaign, {
    schemaAttribute: 'candidateName'
  })
});
const search = new Schema('searches');
search.define({
  list: arrayOf(campaign)
});
// contribution.define({
//   owner: campaign
// });
indivContribution.define({
  owner: campaign,
  listByType: valuesOf(transaction, {
    schemaAttribute: 'bookType'
  })
});
github hackoregon / btc-frontend-2016-ReactRedux / src / client / api / serverApi.js View on Github external
});
// contribution.define({
//   owner: campaign
// });
indivContribution.define({
  owner: campaign,
  listByType: valuesOf(transaction, {
    schemaAttribute: 'bookType'
  })
});
donor.define({
  owner: transaction,
  listByName: valuesOf(transaction, {
    schemaAttribute: 'contributorPayee'
  }),
  relationships: valuesOf(campaign)
});
export const Schemas = {
  CAMPAIGN: campaign,
  CAMPAIGN_ARRAY: arrayOf(campaign),
  TRANSACTION: transaction,
  TRANSACTION_ARRAY: arrayOf(transaction),
  EXPENDITURE: transaction,
  EXPENDITURE_ARRAY: arrayOf(transaction),
  DONOR: donor,
  DONOR_ARRAY: arrayOf(donor),
  LIST: list,
  STATE_CONTRIBUTION: stateContribution,
  STATE_CONTRIBUTION_ARRAY: arrayOf(stateContribution),
  INDIV_CONTRIBUTION: indivContribution,
  INDIV_CONTRIBUTION_ARRAY: arrayOf(indivContribution),
  BIZ_CONTRIBUTION: businessContribution,
github hackoregon / btc-frontend-2016-ReactRedux / src / client / api / serverApi.js View on Github external
const search = new Schema('searches');
search.define({
  list: arrayOf(campaign)
});
// contribution.define({
//   owner: campaign
// });
indivContribution.define({
  owner: campaign,
  listByType: valuesOf(transaction, {
    schemaAttribute: 'bookType'
  })
});
donor.define({
  owner: transaction,
  listByName: valuesOf(transaction, {
    schemaAttribute: 'contributorPayee'
  }),
  relationships: valuesOf(campaign)
});
export const Schemas = {
  CAMPAIGN: campaign,
  CAMPAIGN_ARRAY: arrayOf(campaign),
  TRANSACTION: transaction,
  TRANSACTION_ARRAY: arrayOf(transaction),
  EXPENDITURE: transaction,
  EXPENDITURE_ARRAY: arrayOf(transaction),
  DONOR: donor,
  DONOR_ARRAY: arrayOf(donor),
  LIST: list,
  STATE_CONTRIBUTION: stateContribution,
  STATE_CONTRIBUTION_ARRAY: arrayOf(stateContribution),
github julienvincent / modelizr / src / normalizer.js View on Github external
define() {
        return _valuesOf(this.model.schema ? this.model.schema.model : this.model.define())
    }
}
github julienvincent / modelizr / src / normalizer.js View on Github external
return Normalize(response, _.mapValues(_query, (entity, key) => {

        const model = entity._isUnion ?
            _unionOf(_.mapValues(entity.models, model => model.schema.model), {schemaAttribute: entity.schemaAttribute})
            : entity.model()

        switch (entity._modelType) {
            case "valuesOf":
                return _valuesOf(model)
            case "arrayOf":
                return _arrayOf(model)
        }

        if (Array.isArray(response[key])) return _arrayOf(model)
        if (hasValuesOf(response[key], model)) return _valuesOf(model)

        return model
    }))
}
github julienvincent / modelizr / src / normalizer.js View on Github external
return Normalize(response, _.mapValues(_query, (entity, key) => {

        const model = entity._isUnion ?
            _unionOf(_.mapValues(entity.models, model => model.schema.model), {schemaAttribute: entity.schemaAttribute})
            : entity.model()

        switch (entity._modelType) {
            case "valuesOf":
                return _valuesOf(model)
            case "arrayOf":
                return _arrayOf(model)
        }

        if (Array.isArray(response[key])) return _arrayOf(model)
        if (hasValuesOf(response[key], model)) return _valuesOf(model)

        return model
    }))
}