1
0
mirror of https://github.com/ascribe/onion.git synced 2025-02-14 21:10:27 +01:00

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); 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. 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 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, // if editionList for a specific piece does not exist yet,
// just initialize a new array // just initialize a new array
@ -32,7 +32,7 @@ class EditionListStore {
// page // page
let storeEditionIndex = (page - 1) * pageSize + i; let storeEditionIndex = (page - 1) * pageSize + i;
let editionsForPieces = this.editionList[pieceId]; let editionsForPieces = this.editionList[pieceId];
// if edition already exists, just merge // if edition already exists, just merge
if(editionsForPieces[storeEditionIndex]) { if(editionsForPieces[storeEditionIndex]) {
editionsForPieces[storeEditionIndex] = React.addons.update(editionsForPieces[storeEditionIndex], {$merge: editionListOfPiece[i]}); 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, * We often just have to refresh the edition list for a certain pieceId,
* this method provides exactly that functionality without any side effects * 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 // It may happen that the user enters the site logged in already
// through /editions // through /editions
// If he then tries to delete a piece/edition and this method is called, // 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) => { this.editionList[pieceId].forEach((edition) => {
// Taken from: http://stackoverflow.com/a/519157/1263876 // Taken from: http://stackoverflow.com/a/519157/1263876
@ -144,7 +144,7 @@ class EditionListStore {
if(!this.isEditionListOpenForPieceId[pieceId].show) { if(!this.isEditionListOpenForPieceId[pieceId].show) {
// to clear an array, david walsh recommends to just set it's length to zero // to clear an array, david walsh recommends to just set it's length to zero
// http://davidwalsh.name/empty-array // http://davidwalsh.name/empty-array
this.editionList[pieceId].length = 0; this.editionList[pieceId].length = 0;
} }
} }

View File

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