Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.catch(handleError(fromAction))
},
/** Delete deployment */
deleteDeployment: {
type: 'DEPLOYMENTS_DELETE',
epic: fromAction =>
IoTHubManagerService.deleteDeployment(fromAction.payload)
.map(toActionCreator(redux.actions.deleteDeployment, fromAction))
.catch(handleError(fromAction))
}
});
// ========================= Epics - END
// ========================= Schemas - START
const deploymentSchema = new schema.Entity('deployments');
const deploymentListSchema = new schema.Array(deploymentSchema);
const deployedDevicesSchema = new schema.Entity('deployedDevices');
const deployedDevicesListSchema = new schema.Array(deployedDevicesSchema);
// ========================= Schemas - END
// ========================= Reducers - START
const initialState = { ...errorPendingInitialState, entities: {} };
const insertDeploymentReducer = (state, { payload, fromAction }) => {
const { entities: { deployments }, result } = normalize({ ...payload, isNew: true }, deploymentSchema);
if (state.entities && state.entities.deployments) {
return update(state, {
entities: { deployments: { $merge: deployments } },
items: { $splice: [[0, 0, result]] },
...setPending(fromAction.type, false)
});
}
import omit from 'lodash/omit';
import omitBy from 'lodash/omitBy';
// eslint-disable-next-line import/named
import { normalize, schema } from 'normalizr';
import createReducer from '../utils/create-reducer';
const transitionSchema = new schema.Entity(
'transitions',
{},
{
processStrategy: entity => entity.obj || entity,
}
);
const transitionListSchema = new schema.Array(transitionSchema);
const stateMachineSchema = new schema.Entity('stateMachine', {
transitions: transitionListSchema,
});
const stateMachinesSchema = new schema.Array(stateMachineSchema);
export const normalizers = {
stateMachine: data => normalize(data, stateMachineSchema),
stateMachines: data => normalize(data, stateMachinesSchema),
};
export const actionTypes = {
SET_STATE_MACHINE: 'SET_STATE_MACHINE',
UNSET_STATE_MACHINE: 'UNSET_STATE_MACHINE',
SET_STATE_MACHINES: 'SET_STATE_MACHINES',
};
// Read more about Normalizr: https://github.com/paularmstrong/normalizr
// Schemas for Github API responses.
const userSchema = new schema.Entity('users', {}, {
idAttribute: 'login'
});
const repoSchema = new schema.Entity('repos', {
owner: userSchema
}, {
idAttribute: 'fullName'
});
const userSchemaArray = new schema.Array(userSchema);
const repoSchemaArray = new schema.Array(repoSchema);
// api services
export const fetchUser = login => callApi(`users/${login}`, userSchema);
export const fetchRepo = fullName => callApi(`repos/${fullName}`, repoSchema);
export const fetchStarred = url => callApi(url, repoSchemaArray);
export const fetchStargazers = url => callApi(url, userSchemaArray);
const fileSchema = new schema.Entity('files');
const dirSchema = new schema.Entity('dirs');
const contentSchema = new schema.Union(
{
files: fileSchema,
dirs: dirSchema
},
input => (Array.isArray(input.content) ? 'dirs' : 'files')
);
dirSchema.define({
content: [contentSchema]
});
const sourceSchema = new schema.Entity('sources', {
content: [contentSchema]
});
export const sourceListSchema = new schema.Array(sourceSchema);
const fetchSource = async request => {
const { api, owner, repo, path, branch } = parseGitHubUrl(request.url);
const content = await fetchContents(
// NOTE: We pass in the path as the name however the content is later reparented so is largely irrelevant
path,
api,
request.accessToken,
owner,
repo,
path,
branch
);
const source = {
...request,
// Source extends Dir (if only I had typescript to document this 😞) so
// Schemas for Github API responses.
const userSchema = new schema.Entity('users', {
idAttribute: 'login',
})
const repoSchema = new schema.Entity('repos', {
idAttribute: 'fullName',
})
repoSchema.define({
owner: userSchema,
})
const userSchemaArray = new schema.Array(userSchema)
const repoSchemaArray = new schema.Array(repoSchema)
// api services
export const fetchUser = login => callApi(`users/${login}`, userSchema)
export const fetchRepo = fullName => callApi(`repos/${fullName}`, repoSchema)
export const fetchStarred = url => callApi(url, repoSchemaArray)
export const fetchStargazers = url => callApi(url, userSchemaArray)
it('should return an array of denormalized entities given an array of ids', () => {
const denormalized = denormalize([1, 2], data.entities, new schema.Array(articleSchema));
expect(denormalized).to.be.eql(expectedArticles);
});
});
describe('parsing nested plain objects', () => {
const articleSchema = new schema.Entity('article');
const userSchema = new schema.Entity('user');
articleSchema.define({
likes: new schema.Array({
user: userSchema,
}),
});
const response = {
articles: [{
id: 1,
title: 'Article 1',
likes: [{
user: {
id: 1,
name: 'John',
},
}, {
user: {
id: 2,
.then((json) => {
const normalized = normalize(json, new schema.Array({
playlists: playlistSchema
}, (input) => `${input.kind}s`));
return {
normalized,
json
};
});
}
import { schema } from "normalizr";
export const accountSchema = new schema.Entity("accounts", {}, { idAttribute: (value) => `${value.address}-${value.daoAvatarAddress}` });
export const daoSchema = new schema.Entity("daos", {}, { idAttribute: "address" });
export const proposalSchema = new schema.Entity("proposals", {}, { idAttribute: "proposalId" });
export const redemptionSchema = new schema.Entity("redemptions", {}, { idAttribute: (value) => `${value.proposalId}-${value.accountAddress}` });
export const stakeSchema = new schema.Entity("stakes", {}, { idAttribute: (value) => `${value.proposalId}-${value.stakerAddress}` });
export const voteSchema = new schema.Entity("votes", {}, { idAttribute: (value) => `${value.proposalId}-${value.voterAddress}` });
export const accountList = new schema.Array(accountSchema);
export const daoList = new schema.Array(daoSchema);
export const proposalList = new schema.Array(proposalSchema);
export const redemptionList = new schema.Array(redemptionSchema);
export const stakeList = new schema.Array(stakeSchema);
export const voteList = new schema.Array(voteSchema);
accountSchema.define({
redemptions: redemptionList,
stakes: stakeList,
votes: voteList
});
daoSchema.define({
members: accountList,
proposals: proposalList
});
proposalSchema.define({
redemptions: redemptionList,
stakes: stakeList,
votes: voteList