Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function updatePlayers (nplayers, game) {
// lets deep copy players
let players = jsonpatch.deepClone(nplayers)
// Add missing player if not in players list
game.redPlayers.concat(game.bluePlayers).forEach(p => {
if (players.filter(fp => fp.name === p).length === 0) {
players.push({
name: p,
scored: 0,
gameCount: 0,
winCount: 0,
// trueskill default parameters
mu: 25.000,
sigma: 8.333
})
}
})
socket.on('diff-state', (patch) => {
let state = jsonpatch.deepClone(this.state)
jsonpatch.applyPatch(state, jsonpatch.deepClone(patch))
this.setState(state)
console.log('STATE', state)
})
}
socket.on('diff-state', (patch) => {
let state = jsonpatch.deepClone(this.state)
jsonpatch.applyPatch(state, jsonpatch.deepClone(patch))
this.setState(state)
console.log('STATE', state)
})
}
parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse {
this.dsoParser.parse(deepClone(request), deepClone(data));
if (isNotEmpty(data.payload)
&& isNotEmpty(data.payload._links)
&& this.isSuccessStatus(data.statusCode)) {
const dataDefinition = this.processResponse(data.payload, request);
return new SubmissionSuccessResponse(dataDefinition, data.statusCode, data.statusText, this.processPageInfo(data.payload));
} else if (isEmpty(data.payload) && this.isSuccessStatus(data.statusCode)) {
return new SubmissionSuccessResponse(null, data.statusCode, data.statusText);
} else {
return new ErrorResponse(
Object.assign(
new Error('Unexpected response from server'),
{statusCode: data.statusCode, statusText: data.statusText}
)
);
}
}
(path: string[]) => {
const browsePath = [...path];
const newPage = deepClone(selectedPage);
let parent: WegasComponent | undefined = undefined;
let component: WegasComponent = newPage;
while (browsePath.length > 0) {
if (component.props.children) {
parent = component;
component = component.props.children[Number(browsePath[0])];
browsePath.splice(0, 1);
} else {
return { newPage };
}
}
return { newPage, component, parent };
},
[selectedPage],
recordPatch: async patch => {
const patchResults = jsonPatch.applyPatch(
previousState,
jsonPatch.deepClone(patch)
)
},
}
eventService.subscribeSelection(async selection => {
let properties = null;
try {
properties = selection ? await new ModelService().getProperties(selection.$metadata.$model) : null;
} catch (exc) {
print(`*** Error fetching twin properties: ${exc}`, "error");
}
this.properties = properties;
this.original = this.updated = selection ? await applyDefaultValues(properties, deepClone(selection)) : null;
this.setState({ changed: false, selection, patch: null });
if (selection) {
this.editor.set(this.original);
}
});
}
(path: string[]) => {
const newPage: Page = deepClone(selectedPage);
let parent: WegasComponent = newPage;
const browsePath = [...path];
while (browsePath.length > 0) {
if (parent.props.children) {
if (browsePath.length == 1) {
parent.props.children.splice(Number(browsePath[0]), 1);
patchPage(pagesState.selectedPage, newPage);
return;
}
parent = parent.props.children[Number(browsePath[0])];
}
browsePath.splice(0, 1);
}
},
[selectedPage, pagesState.selectedPage, patchPage],