Verbs
const selectClient = function (clientState, client) {
return {
clients: clientState.clients,
currentClient: client,
};
};
const selectClient = (clientState, client) => {
return {
clients: clientState.clients,
currentClient: client,
};
};
const selectClient = (clientState, client) => ({
clients: clientState.clients,
currentClient: client,
});
const selectClient = (clientState, client) => {
return {
clients: clientState.clients,
currentClient: client,
};
};
const spiderMan = {
id: '1000',
firstName: 'Peter',
lastName: 'Parker',
company: 'Student',
};
selectClient(initialState, spiderMan);
const clientsState = selectClient(initialState, spiderMan);
class ClientStore {
clients: Client[];
currentClient: Client;
load(clients) {
this.clients = clients;
}
read() {
return this.clients;
}
select(client) {
this.currentClient = client;
}
create(client) {
this.clients.push(client);
}
}
const clientStore = new ClientStore();
clientStore.load(clients);
clientStore.select(clients[0]);
const spiderMan = {
id: '1000',
firstName: 'Peter',
lastName: 'Parker',
company: 'Student',
};
clientStore.create(spiderMan);
In Practice
class Store {
state;
constructor(state) {
}
getState() {
}
select(key) {
}
}
class Store {
state;
constructor(state) {
this.state = state;
}
getState() {
return this.state;
}
select(key) {
return this.state[key];
}
}
Challenges
- Create a ProjectStore class
- Add a state property to the class
- Add a constructor to the class that accepts a state parameter
- Add a getState method
- Add a select method
- Instantiate the ProjectStore class with the initialState object
- Call select on the class to get the projects collection