1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-30 13:41:57 +02:00
onion/js/stores/piece_store.js

33 lines
754 B
JavaScript
Raw Normal View History

'use strict';
import { alt } from '../alt';
2015-06-08 18:14:25 +02:00
import PieceActions from '../actions/piece_actions';
2015-05-26 10:41:41 +02:00
class PieceStore {
constructor() {
2015-05-26 13:33:35 +02:00
this.piece = {};
2015-10-19 15:58:05 +02:00
this.pieceError = null;
2015-06-08 18:14:25 +02:00
this.bindActions(PieceActions);
2015-05-26 10:41:41 +02:00
}
onUpdatePiece(piece) {
this.piece = piece;
2015-10-19 15:58:05 +02:00
this.pieceError = null;
2015-05-26 10:41:41 +02:00
}
2015-07-13 18:13:16 +02:00
onUpdateProperty({key, value}) {
if(this.piece && key in this.piece) {
this.piece[key] = value;
} else {
throw new Error('There is no piece defined in PieceStore or the piece object does not have the property you\'re looking for.');
}
}
2015-10-19 15:58:05 +02:00
onPieceFailed(err) {
this.pieceError = err;
}
2015-05-26 13:33:35 +02:00
}
2015-05-26 10:41:41 +02:00
2015-06-15 08:44:44 +02:00
export default alt.createStore(PieceStore, 'PieceStore');