Creating a Seller Data Object in Redux
In the previous lesson we created data models for our database. In this lesson we will write some generator functions that will be used to form data objects with specific values.
Let's open our product app, and in it the file server.js
. First, let's create a template object for the seller data. The first thing we'll do is collect the names of our sellers, and we had 4
of them, into an array right after the import lines:
const selNames = ['Super Power', 'Miracle Life', 'Dolls&Toys', 'Granny']
And below, after creating the database model db
, we will write a function with which we will create objects with seller data createSellerData
:
const createSellerData = () => {}
Our function will take the seller name number in the selNames
array as a parameter, we will use it to find the desired name and return an object with the name
property and the corresponding name as a value:
const createSellerData = (num) => {
const name = selNames[num]
return {
name: `${name}`,
}
}
Let's write a standard function below to get a random integer, we'll need it later:
function getRandInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min
}
Open your app with students. After reviewing the material of this lesson, write a function to create an object with the teacher's data. Remember that you have another property for it - the subject. Hint: if you want, you can choose a value for this property randomly, for example from an array.