Shopping List Domain Model
Note: This is a work in progress. Use exact versions when installing (e.g. --save-exact
) as backwards-incompatible changes may be introduced.
Shopping List is a series of Offline First demo apps, each built using a different stack. This is a JavaScript implementation of the domain model for the Shopping List app. This package may be used in Vanilla JS, Polymer, React, Preact, Vue.js, Ember.js, React Native, Ionic, Cordova, Electron, and any other JavaScript implementation of the Shopping List demo app.
Installation
This package can be installed via npm:
npm install ibm-shopping-list-model
To use the Shopping List Factory and the Shopping List Repository PouchDB implementation:
const ShoppingListFactory ShoppingListRepositoryPouchDB = ;
Usage
Shopping Lists
Making a New Shopping List
Use a Shopping List Factory to make a new Shopping List:
const ShoppingListFactory = ; const shoppingListFactory = ; let shoppingList = shoppingListFactory; console; // list:…console; // undefinedconsole; // Groceries
Creating a Shopping List in a Database
Use a Shopping List Repository to create a Shopping List in a database:
const ShoppingListFactory ShoppingListRepositoryPouchDB = ;const PouchDB = ;PouchDB; const shoppingListFactory = ;const db = "shopping-list";const shoppingListRepository = db; let shoppingList = shoppingListFactory; shoppingListRepository;
Reading a Shopping List from a Database
Use a Shopping List Repository to read a Shopping List from a database when you know the _id
value:
const ShoppingListRepositoryPouchDB = ;const PouchDB = ;PouchDB; const db = "shopping-list";const shoppingListRepository = db; // Replace "list:cj6mj1zfj000001n1ugjfkj33" with the _id value for your Shopping ListshoppingListRepository;
Finding a List of Shopping Lists from a Database
Use a Shopping List Repository to find a List of Shopping Lists from a database:
const ShoppingListFactory ShoppingListRepositoryPouchDB = ;const PouchDB = ;PouchDB; const shoppingListFactory = ;const db = "shopping-list";const shoppingListRepository = db; let shoppingList01 = shoppingListFactory;let shoppingList02 = shoppingListFactory; let listOfShoppingLists = shoppingListFactory; shoppingListRepository;
Modifying a Shopping List
Shopping Lists are Immutable.js Record objects. Use the set
method or the mergeDeep
method to make a modified copy of a Shopping List:
const ShoppingListFactory = ; const shoppingListFactory = ; let shoppingList = shoppingListFactory; // Shopping List objects are immutable, so we assign the new object to our local shoppingList variableshoppingList = shoppingList; console; // true shoppingList = shoppingList; console; // Groceries for Dinner Partyconsole; // false
Updating a Shopping List in a Database
Use a Shopping List Repository to update a Shopping List in a database, after saving it to a database:
const ShoppingListFactory ShoppingListRepositoryPouchDB = ;const PouchDB = ;PouchDB; const shoppingListFactory = ;const db = "shopping-list";const shoppingListRepository = db; let shoppingList = shoppingListFactory; shoppingListRepository;
Deleting a Shopping List from a Database
Use a Shopping List Repository to delete a Shopping List (and all of its Shopping List Items) from a database, after saving it to a database:
const ShoppingListFactory ShoppingListRepositoryPouchDB = ;const PouchDB = ;PouchDB; const shoppingListFactory = ;const db = "shopping-list";const shoppingListRepository = db; let shoppingList = shoppingListFactory; shoppingListRepository;
Shopping List Items
Making a New Shopping List Item
Use a Shopping List Factory to make a new Shopping List Item attached to a Shopping List:
const ShoppingListFactory = ; const shoppingListFactory = ; let shoppingList = shoppingListFactory; let shoppingListItem = shoppingListFactory; console; // item:…console; // undefinedconsole; // Mangos
Creating a Shopping List Item in a Database
Use a Shopping List Repository to create a Shopping List Item in a database:
const ShoppingListFactory ShoppingListRepositoryPouchDB = ;const PouchDB = ;PouchDB; const shoppingListFactory = ;const db = "shopping-list";const shoppingListRepository = db; let shoppingList = shoppingListFactory; let shoppingListItem = shoppingListFactory; shoppingListRepository;
Reading a Shopping List Item from a Database
Use a Shopping List Repository to read a Shopping List Item from a database when you know the _id
value:
const ShoppingListRepositoryPouchDB = ;const PouchDB = ;PouchDB; const db = "shopping-list";const shoppingListRepository = db; // Replace "item:cj6mn7e36000001p9n14fgk6s" with the _id value for your Shopping ListshoppingListRepository;
Finding a List of Shopping List Items for a Shopping List from a Database
Use a Shopping List Repository to find a List of Shopping List Items from a database when you know the _id
value of the parent Shopping List:
const ShoppingListFactory ShoppingListRepositoryPouchDB = ;const PouchDB = ;PouchDB; const shoppingListFactory = ;const db = "shopping-list";const shoppingListRepository = db; let shoppingList = shoppingListFactory; let shoppingListItem01 = shoppingListFactory;let shoppingListItem02 = shoppingListFactory;let shoppingListItem03 = shoppingListFactory; let listOfGroceriesItems = shoppingListFactory; shoppingListRepository;
Finding a Count of Shopping List Items for a Shopping List from a Database
Use a Shopping List Repository to find a count of Shopping List Items from a database when you know the _id
value of the parent Shopping List:
const ShoppingListFactory ShoppingListRepositoryPouchDB = ;const PouchDB = ;PouchDB; const shoppingListFactory = ;const db = "shopping-list";const shoppingListRepository = db; let shoppingList = shoppingListFactory; let shoppingListItem01 = shoppingListFactory;let shoppingListItem02 = shoppingListFactory;let shoppingListItem03 = shoppingListFactory; let listOfGroceriesItems = shoppingListFactory; shoppingListRepository;
Finding a Count of Checked Shopping List Items for a Shopping List from a Database
Use a Shopping List Repository to find a count of checked Shopping List Items from a database when you know the _id
value of the parent Shopping List:
const ShoppingListFactory ShoppingListRepositoryPouchDB = ;const PouchDB = ;PouchDB; const shoppingListFactory = ;const db = "shopping-list";const shoppingListRepository = db; let shoppingList = shoppingListFactory; let shoppingListItem01 = shoppingListFactory;let shoppingListItem02 = shoppingListFactory;let shoppingListItem03 = shoppingListFactory; let listOfGroceriesItems = shoppingListFactory; shoppingListRepository;
Finding a Count of Shopping List Items by Shopping List from a Database
Use a Shopping List Repository to find a count of Shopping List Items by Shopping List from a database:
const ShoppingListFactory ShoppingListRepositoryPouchDB = ;const PouchDB = ;PouchDB; const shoppingListFactory = ;const db = "shopping-list";const shoppingListRepository = db; let shoppingList01 = shoppingListFactory;let shoppingList02 = shoppingListFactory; let listOfShoppingLists = shoppingListFactory; let shoppingListItem01 = shoppingListFactory;let shoppingListItem02 = shoppingListFactory;let shoppingListItem03 = shoppingListFactory;let shoppingListItem04 = shoppingListFactory;let shoppingListItem05 = shoppingListFactory; let listOfShoppingListItems = shoppingListFactory; shoppingListRepository;
Finding a Count of Checked Shopping List Items by Shopping List from a Database
Use a Shopping List Repository to find a count of checked Shopping List Items by Shopping List from a database:
const ShoppingListFactory ShoppingListRepositoryPouchDB = ;const PouchDB = ;PouchDB; const shoppingListFactory = ;const db = "shopping-list";const shoppingListRepository = db; let shoppingList01 = shoppingListFactory;let shoppingList02 = shoppingListFactory; let listOfShoppingLists = shoppingListFactory; let shoppingListItem01 = shoppingListFactory;let shoppingListItem02 = shoppingListFactory;let shoppingListItem03 = shoppingListFactory;let shoppingListItem04 = shoppingListFactory;let shoppingListItem05 = shoppingListFactory; let listOfShoppingListItems = shoppingListFactory; shoppingListRepository;
Modifying a Shopping List Item
Shopping List Items are Immutable.js Record objects. Use the set
method or the mergeDeep
method to make a modified copy of a Shopping List Item:
const ShoppingListFactory = ; const shoppingListFactory = ; let shoppingListItem = shoppingListFactory; // Shopping List Item objects are immutable, so we assign the new object to our local shoppingListItem variableshoppingListItem = shoppingListItem; console; // true shoppingListItem = shoppingListItem; console; // Organic Mangosconsole; // false
Updating a Shopping List Item in a Database
Use a Shopping List Repository to update a Shopping List Item in a database, after saving it to a database:
const ShoppingListFactory ShoppingListRepositoryPouchDB = ;const PouchDB = ;PouchDB; const shoppingListFactory = ;const db = "shopping-list";const shoppingListRepository = db; let shoppingList = shoppingListFactory; let shoppingListItem = shoppingListFactory; shoppingListRepository;
Deleting a Shopping List Item from a Database
Use a Shopping List Repository to delete a Shopping List Item from a database, after saving it to a database:
const ShoppingListFactory ShoppingListRepositoryPouchDB = ;const PouchDB = ;PouchDB; const shoppingListFactory = ;const db = "shopping-list";const shoppingListRepository = db; let shoppingList = shoppingListFactory; let shoppingListItem = shoppingListFactory; shoppingListRepository;
Shopping List Item Lists
Making a New Shopping List Item List
Use a Shopping List Factory to make a new Shopping List Item List:
const ShoppingListFactory = ; const shoppingListFactory = ; let shoppingList = shoppingListFactory; let shoppingListItem01 = shoppingListFactory;let shoppingListItem02 = shoppingListFactory; let listOfGroceriesItems = shoppingListFactory; console; // Mangosconsole; // Oranges
Modifying Lists of Shopping Lists or Shopping List Items
Lists of Shopping Lists and Shopping List Items are Immutable.js Lists objects. Use the push
method, the delete
method, or other persistent change List methods to make a modified copy of a List:
const ShoppingListFactory = ; const shoppingListFactory = ; let shoppingList = shoppingListFactory; let shoppingListItem01 = shoppingListFactory;let shoppingListItem02 = shoppingListFactory; let listOfGroceriesItems = shoppingListFactory; console; // Mangosconsole; // Oranges let shoppingListItem03 = shoppingListFactory; listOfGroceriesItems = listOfGroceriesItems; console; // Mangosconsole; // Orangesconsole; // Pears listOfGroceriesItems = listOfGroceriesItems; console; // Orangesconsole; // Pears