dvbsknd / fcc-frontendprojects Goto Github PK
View Code? Open in Web Editor NEWHousing various freeCodeCamp exercises for the front-end frameworks module.
Housing various freeCodeCamp exercises for the front-end frameworks module.
There's no need to encapsulate all the logic in one function. It can be separated into multiple handlers. For example:
const handleDecrement = () => ({state , breakLength}) => {
let newTime = breakLength <= 60 ? 60 : breakLength - 60;
if (state === STATE.stopped) changeBreak(newTime);
}
<button type='button' id='break-decrement' onClick={handleDecrement({state, breakLength})}>
<i className="fas fa-arrow-alt-circle-left"></i>
</button>
BTW
const handleDecrement = () => ({state , breakLength}) => {
// is equivalent to
function handleDecrement({state , breakLength}) {
// if
<button type='button' id='break-decrement' onClick={() => handleDecrement({state, breakLength})}>
// we just 'curry' the first function invocation.
Between lines 108 - 140 there are a lot of references to 60
. Best to create a constant variable, something like ONE_SEC = 60
and replace all instances. Better readability and easier to change, if you decide to change the duration for whatever reason.
The term DEFAULTS
is confusing here. DEFAULTS
usually refers to a constant, unchanging value. I think what you're after here is an initial value. Again, probably best to namespace it to the clock.
When passing in props to a component, it's good to think of them as being as benign to a component as possible. The reason for this is that any special logic should be handled prior to send it down the wire. The component's responsibility should be to to just render the output.
In lines 181-185 it's best to just pass in the variables and let the components deal with how they get rendered (in this case, they use a formatTime
utility function). Make sense?
You're already pulling out the handler on line 203. You can update all instances of props.handler
. Might as well destructuring any other keys from props while you're at it.
There are only two hard things in Computer Science: cache invalidation and naming things.
-- Martin Fowler quoting Phil Karlton
In this case, a worthy fix is to namespace the concepts:
STATE
can become CLOCK_STATE
MODE
can become CLOCK_MODE
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.