Hello readers, this App include :
- React 16.4.0
- ECMAScript 6 and JSX support
- React Router v4
- Component testing using Enzyme and Jest
- Code Coverage
- Latest Webpack (v.3.11.0) and Webpack Dev Server (v.2.9.5) with Scope Hoisting enabled
- Hot Module Replacement using react-hot-loader
- ES6 linting with continuous linting on file change
- SCSS support
- Separate CSS stylesheets generation
- Production Config
- Custom Babel Preset with Decorators, Class Properties, Rest/Spread operator support
Make sure you have the latest Stable or LTS version of Node.js installed.
git clone https://github.com/kbenrafik/products-compare
- Run
npm install
oryarn install
- Start the dev server using
npm start
- Open http://localhost:8080
npm start
- start the dev servernpm run clean
- delete the dist foldernpm run production
- create a production ready build indist
foldernpm run lint
- execute an eslint checknpm test
- run all testsnpm run test:watch
- run all tests in watch modenpm run coverage
- generate code coverage report in thecoverage
folder
I decide to work with React as UI library and some extra helpers|libraries to try to make the app better and easy to maintain.
I have implemented the following behaviors for the comparator :
- Show and hide products
- Highlight differences between product features
- Features should be in alphabetical order by feature name
- Badges should be placed before features
- Exclude given features
So let's start about the exciting things :D
I have made 2 major components that can be reuse again :
- CompareProducts
- expecting list of SKU
- output will be loading | no products found | products compare
- Product (PureComponent because we just render the given props)
- input product object
- output is the html (just rendring)
Hmm, I tried to separate the concerns I mean all the logic about the compare are on API folder and React will only render
So here we should get the products and prepare them for the component CompareProducts, I mean :
- Get data from the endpoint
- features should be in alphabetical order
- put bagdes feature at the first item
- Know which feature is different
All logic are on API folder, I have created two classes for Product and Products.
I keep it simple and easy :
- Separate the concern (login and rendering)
- Use understandable naming (like: boolean isReady...)
- Use linting for the quality code and also for other developers (airbnb .eslintrc)
- Documentation (JSDoc)
- Testing for API and React Components (I have promise Samuel to send him the solution in one week, I didn't have much time to cover all things that I was planing, if I have time I woud love to finish all tests)
- Use SCSS with BEM as a methodology
- Separate CSS stylesheets generation
- Webpack : I have added many module loaders for SCSS => CSS, ES6, and for static files (url-loader) and one plugin for eslint
- Sass/Less : SCSS
- Any CSS methodology : BEM I love it
- Responsiveness : I think I cover 60% without any library, if I have the time I would love to finish it
- Browser backward compatibility (IE11) : I used flex, it works on IE11 but with some issues