- implementing immutable.js
This commit is contained in:
43
app/domain/Item.js
Normal file
43
app/domain/Item.js
Normal file
@@ -0,0 +1,43 @@
|
||||
import { List, Record } from 'immutable';
|
||||
|
||||
export default class Item extends Record({
|
||||
bidCount: 0,
|
||||
bidIncrement: 10,
|
||||
catalogNumber: null,
|
||||
currentPrice: 0,
|
||||
description: null,
|
||||
donor: null,
|
||||
end: null,
|
||||
estimatedValue: null,
|
||||
eventId: null,
|
||||
hideAfterEnd: false,
|
||||
hideBeforeStart: false,
|
||||
id: null,
|
||||
images: new List(),
|
||||
isShippable: false,
|
||||
notifyOnAvailable: false,
|
||||
quantityAvailable: 1,
|
||||
soldCount: 0,
|
||||
start: null,
|
||||
startingPrice: null,
|
||||
subtitle: null,
|
||||
title: null,
|
||||
type: null,
|
||||
shippingCost: 0,
|
||||
}) {
|
||||
get isSoldOut() {
|
||||
return this.quantityAvailable > this.soldCount;
|
||||
}
|
||||
|
||||
get totalWithShipping() {
|
||||
return this.currentPrice + this.shippingCost;
|
||||
}
|
||||
}
|
||||
|
||||
Item.fromJS = (data = {}) => {
|
||||
return new Item({
|
||||
id: data._id,
|
||||
...data,
|
||||
images: List(data.images),
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user