types .model('String', { value: types.maybeNull(types.string) }) .actions(self => { return { clear() { self.value = undefined; }, setValue(s) { self.value = s; } }; }) .views(self => ({ get hasValue() { return self.value && self.value.trim() !== ''; } }))
.views(self => ({ get finalCommand() { return self.listOfCommands.join(' && ');
.views(self => ({ get valid() { return [self.editor, self.projectsPath].every(e => !isEmptyString(e));
.views(self => ({ get status() { if (self.running) {
types.model("MemberInfo", { ID: types.identifierNumber, FirstName: types.string, LastName: types.string, }).views(self => ({ get fullName() { return `${self.FirstName} ${self.LastName}`; } }))
types .model("AuthorsStore", { authors: types.map(Author) }) .views(self => ({ get blog() { return getParent(self); }, get allAuthors() { return self.authors.values(); }, get currentAuthor() { if (!self.blog.auth.isAuthor || !self.blog.auth.user) { return null; } const authorName = self.blog.auth.user.authorName; return self.allAuthors.find(author => author.id === authorName) || null; } }))
types.model({ books: types.array(Book) }) .views(self => ({ get readBooks() { return self.books.filter(book => book.read) }, booksByAuthor(author) { return self.books.filter(book => book.author === author) } }) ) .actions(self => ({ addBook(book) { self.books.push(book) }, remove(book) { destroy(book) } })) .create({ books: [] })
types .model("CategoriesStore", { categories: types.map(Category), areCategoriesLoaded: types.boolean }) .views(self => ({ get blog() { return getParent(self); }, get allCategories() { return self.categories.values(); } })) .actions(self => { const fetchCategories = flow(function* fetchCategories() { try { const querySnapshot = yield firestore.collection("categories").get(); querySnapshot.forEach(doc => { const category = doc.data(); self.categories.put(category); }); self.areCategoriesLoaded = true; } catch (e) {} }); return { fetchCategories }; })
types .model('ShoppinCartStore', { products: types.array(types.reference(ProductModel)), }) .views(self => ({ get totalProducts() { return self.products.length; }, get totalAmount() { return self.products .reduce((acc, current) => acc + parseFloat(current.totalPrice), 0) .toFixed(2); }, get productsList() { return self.products.slice(); }, })) .actions(self => ({ addProduct(product) { const entry = self.products.find(el => el.id === product.id); if (!entry) { self.products.push(product); } }, removeProduct(product) { self.products = self.products.filter(el => el.id !== product.id); }, }))
}, })) .views(self => ({ get user() { return getParent(self, 2);
types.model('WishList', { items: types.optional(types.array(WishListItem), []), }) .actions(self => ({ add(item) { self.items.push(item) } })) .views(self => ({ get totalPrice() { return self.items.reduce((sum, entry) => sum + entry.price, 0) } }))
inCart: false, }) .views(self => ({ get price() { return self.unityPrice.toFixed(2);
addresses: types.optional(types.array(UserAddressModel), []), }) .views(self => ({ get auth() { return getParent(self);
types .model("UIStore", { collapsedSidebar: false, languages: types.map(Language) }) .views(self => ({ get blog() { return getParent(self); }, get allLanguages() { return self.languages.values(); } })) .actions(self => ({ toggleSidebar() { self.collapsedSidebar = !self.collapsedSidebar; }, closeSidebar() { self.collapsedSidebar = false; }, openSidebar() { self.collapsedSidebar = true; } }))
types.model('Books', { books: types.array(Book) }) .views(self => ({ get readBooks(){ return self.books.filter(book => book.read) }, booksByAuthor(author){ return self.books.filter(book => book.author === author) } })) .actions(self => ({ addBook(book) { self.books.push(book) }, removeBook(book){ destroy(book) } })) .create({ books: [{ title: 'Ready Player One', author: 'Ernest Cline', read: true }] })