Small style changes for Piece and Edition ListStores

This commit is contained in:
Brett Sun 2016-01-13 17:14:09 +01:00
parent 466872affb
commit ea18b31db1
2 changed files with 14 additions and 15 deletions

View File

@ -12,7 +12,7 @@ class EditionListStore {
this.bindActions(EditionsListActions);
}
onUpdateEditionList({pieceId, editionListOfPiece, page, pageSize, orderBy, orderAsc, count, filterBy}) {
onUpdateEditionList({ pieceId, editionListOfPiece, page, pageSize, orderBy, orderAsc, count, filterBy }) {
/*
Basically there are two modes an edition list can be updated.
@ -20,7 +20,7 @@ class EditionListStore {
2. The elements are already defined => merge current objects with the new ones from the server
*/
for(let i = 0; i < editionListOfPiece.length; i++) {
for (let i = 0; i < editionListOfPiece.length; i++) {
// if editionList for a specific piece does not exist yet,
// just initialize a new array
@ -32,7 +32,7 @@ class EditionListStore {
// page
let storeEditionIndex = (page - 1) * pageSize + i;
let editionsForPieces = this.editionList[pieceId];
// if edition already exists, just merge
if(editionsForPieces[storeEditionIndex]) {
editionsForPieces[storeEditionIndex] = React.addons.update(editionsForPieces[storeEditionIndex], {$merge: editionListOfPiece[i]});
@ -60,7 +60,7 @@ class EditionListStore {
* We often just have to refresh the edition list for a certain pieceId,
* this method provides exactly that functionality without any side effects
*/
onRefreshEditionList({pieceId, filterBy = {}}) {
onRefreshEditionList({ pieceId, filterBy = {} }) {
// It may happen that the user enters the site logged in already
// through /editions
// If he then tries to delete a piece/edition and this method is called,
@ -102,7 +102,7 @@ class EditionListStore {
});
}
onSelectEdition({pieceId, editionId, toValue}) {
onSelectEdition({ pieceId, editionId, toValue }) {
this.editionList[pieceId].forEach((edition) => {
// Taken from: http://stackoverflow.com/a/519157/1263876
@ -144,7 +144,7 @@ class EditionListStore {
if(!this.isEditionListOpenForPieceId[pieceId].show) {
// to clear an array, david walsh recommends to just set it's length to zero
// http://davidwalsh.name/empty-array
this.editionList[pieceId].length = 0;
}
}

View File

@ -31,7 +31,7 @@ class PieceListStore {
this.requestActions = {};
this.bindActions(PieceListActions);
}
onUpdatePieceList({ page, pageSize, search, pieceList, orderBy, orderAsc, pieceListCount, unfilteredPieceListCount, filterBy }) {
this.page = page;
this.pageSize = pageSize;
@ -60,13 +60,13 @@ class PieceListStore {
* point anyway. Then, this problem is automatically resolved.
*/
pieceList.forEach((piece, i) => {
let oldPiece = this.pieceList[i];
if(oldPiece) {
const oldPiece = this.pieceList[i];
if (oldPiece) {
piece = React.addons.update(piece, {
show: { $set: oldPiece.show }
});
}
});
this.pieceList = pieceList;
@ -76,12 +76,11 @@ class PieceListStore {
this.requestActions = res.actions;
}
onUpdatePropertyForPiece({pieceId, key, value}) {
let filteredPieceList = this.pieceList.filter((piece) => piece.id === pieceId);
onUpdatePropertyForPiece({ pieceId, key, value }) {
const filteredPieceList = this.pieceList.filter((piece) => piece.id === pieceId);
if(filteredPieceList.length === 1) {
let piece = filteredPieceList[0];
if (filteredPieceList.length === 1) {
const piece = filteredPieceList[0];
piece[key] = value;
} else {
throw new Error('Could not find a matching piece in piece list since its either not there or piecelist contains duplicates.');