Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CRIO_BYTES
me_redux
Commits
fc93eed9
Commit
fc93eed9
authored
1 year ago
by
Mohak Trivedi
Browse files
Options
Download
Email Patches
Plain Diff
Activity 1 STUB created
parent
b7b36317
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
69 deletions
+21
-69
src/App.js
src/App.js
+9
-13
src/actions/index.js
src/actions/index.js
+0
-20
src/actions/types.js
src/actions/types.js
+0
-3
src/styles.css
src/styles.css
+1
-1
store.js
store.js
+11
-32
No files found.
src/App.js
View file @
fc93eed9
i
mport
store
from
"
../
store
"
;
// TODO: I
mport
the
store from store
.js
import
"
./styles.css
"
;
export
default
function
App
()
{
const
handleIncrement
=
()
=>
{
store
.
dispatch
({
type
:
"
INCREMENT_CARS
"
});
// console.log(store.getState());
};
const
handleDecrement
=
()
=>
{
store
.
dispatch
({
type
:
"
DECREMENT_CARS
"
});
// console.log(store.getState());
};
const
handleSetHundred
=
()
=>
{
store
.
dispatch
({
type
:
"
SET_CARS
"
,
payload
:
{
cars
:
100
}
});
};
// TODO: Log the store state and the cars from the store state.
const
handleIncrement
=
()
=>
{};
const
handleDecrement
=
()
=>
{};
return
(
<
div
className
=
"
App
"
>
...
...
@@ -23,7 +20,6 @@ export default function App() {
<
div
className
=
"
controls
"
>
<
button
onClick
=
{
handleIncrement
}
>+<
/button
>
<
button
onClick
=
{
handleDecrement
}
>-<
/button
>
<
button
onClick
=
{
handleSetHundred
}
>
Set
100
<
/button
>
<
/div
>
<
/div
>
<
/div
>
...
...
This diff is collapsed.
Click to expand it.
src/actions/index.js
deleted
100644 → 0
View file @
b7b36317
import
{
DECREMENT_CARS
,
INCREMENT_CARS
,
SET_CARS
}
from
"
./types
"
;
export
const
incrementCars
=
()
=>
{
return
{
type
:
INCREMENT_CARS
};
};
export
const
decrementCars
=
()
=>
{
return
{
type
:
DECREMENT_CARS
};
};
export
const
setCars
=
(
value
)
=>
{
return
{
type
:
SET_CARS
,
payload
:
{
cars
:
value
}
};
};
This diff is collapsed.
Click to expand it.
src/actions/types.js
deleted
100644 → 0
View file @
b7b36317
export
const
INCREMENT_CARS
=
"
INCREMENT_CARS
"
;
export
const
DECREMENT_CARS
=
"
DECREMENT_CARS
"
;
export
const
SET_CARS
=
"
SET_CARS
"
;
This diff is collapsed.
Click to expand it.
src/styles.css
View file @
fc93eed9
...
...
@@ -14,4 +14,4 @@
.controls
{
display
:
flex
;
gap
:
10px
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
store.js
View file @
fc93eed9
import
{
DECREMENT_CARS
,
INCREMENT_CARS
,
SET_CARS
}
from
"
./src/actions/types
"
;
const
initialState
=
{
cars
:
0
};
const
createStore
=
(
reducer
)
=>
{
const
createStore
=
()
=>
{
const
store
=
{};
store
.
state
=
initialState
;
store
.
getState
=
()
=>
{
return
store
.
state
;
};
// TODO: Implement the getState() such that it returns the state.
store
.
getState
=
()
=>
{
}
store
.
dispatch
=
(
action
)
=>
{
store
.
state
=
reducer
(
store
.
state
,
action
);
console
.
log
(
store
.
getState
());
//User to implement it in future milestones
store
.
incrementCount
=
()
=>
{
};
return
store
;
};
const
initialState
=
{
cars
:
0
};
const
reducer
=
(
state
=
initialState
,
action
)
=>
{
switch
(
action
.
type
)
{
case
INCREMENT_CARS
:
{
const
newState
=
{
...
store
.
state
,
cars
:
store
.
state
.
cars
+
1
};
return
newState
;
}
case
DECREMENT_CARS
:
{
const
newState
=
{
...
store
.
state
,
cars
:
store
.
state
.
cars
-
1
};
return
newState
;
}
case
SET_CARS
:
{
const
newState
=
{
...
store
.
state
,
cars
:
action
.
payload
.
cars
};
return
newState
;
}
default
:
return
state
;
}
};
const
store
=
createStore
(
reducer
);
const
store
=
createStore
();
export
default
store
;
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment