Interactive frontend development
Urmas Talimaa
SaleMove Inc
Developing React Component Look and Feel
When adding a React Component to a non-trivial application it is not feasible to
Developing React Component Look and Feel
Developing React Component Look and Feel
Idea:
Create a React application with only one component, develop the application in ordinary fashion: using a browser.
Developing React Component Look and Feel
Note that for this to work seamlessly
React Storybook
One implementation of this idea is React Storybook
A storybook allows declaring stories, each of which will just be a rendering of a component in a particular state.
The stories can be viewed and switched through a convenient interface.
When a component is changed, the story either hot-reloads or refreshes automatically.
Example
Visual tests?
There are various tools that test website visuals.
Either way such tests can be included in the build-chain.
When going with an actual browser + screenshot approach, it is usually better to offload running such tests to a Continuous Integration (CI) machine.
Visual tests!
A storybook setup greatly simplifies creating and maintaining visual tests as the tests can be created for the isolated components.
Trying to use the full application and create the required state can be very complex and hard to maintain.
Pull request
diff example
Designers will eat this up
Middlewares for handling side effects
Middlewares for handling side effects
If an application requires chaining multiple asynchronous behaviours and having precise termination control, simple solutions are not enough.
Remember: Anything that deals with non-trivial asynchronous behaviour is always far more complex than you expect.
Middlewares for handling side effects
In such a case, avoid rolling out your own concurrency framework and use a library.
Good ones provide a declarative way for describing the desired side effects and their composition AND provide ways to test the declarations.
Managing asynchronous side effects
Example library: https://github.com/redux-saga/redux-saga
Note that this library is built in exactly the same way as our own middlewares. The container components that dispatch actions know nothing about what goes on behind the scenes nor have references to the XMLHttpRequests or similar objects.
The saga middleware hooks up to plain actions and dispatches separate actions when required.
Managing asynchronous side effects
The sagas are written using generator functions which is an ES6 feature for chaining asynchronous operations without requiring nested callbacks.
Generator function documentation
Two consecutive yields after transpilation
Generator functions are not intuitive at first, but the idea of managing side-effects in a declarative way in a middleware should be familiar by now.
Observable streams
Managing asynchronous side effects
Remember:
Declarative + Testable = Good times
Managing asynchronous side effects
Whatever asynchronous model you use,
sync it with the redux store at every step.
You don’t want to have complex, long running asynchronous behaviour that
Thanks for hanging on
Front-end development
Thanks for hanging on
Exam
Sample exam questions
Following sample question list is not comprehensive.
If you understand the core concepts, principles and terminology of the technologies/techniques discussed on the slides you should have no problem answering the questions.�
Sample question
What is a transpiler?
Sample question
Identify/characterize a
Sample question
Characterize
Sample question
Identify a pure function React component
Sample question
Identify/characterize a presentational/container React component
Sample question
Identify/characterize Redux
Sample question
Which of the following characterizes a `fetch`/WebSocket?
Sample question
What is the history API in the context of web applications?
Sample question
How to pause JavaScript execution at a specific line in JavaScript in a web browser?
Sample question
Write a React component named Names, that when provided array of arbitrary names ({names: [‘foo’, ‘bar’]}) as props will output the following HTML equivalent� <ul id=”names”>� <li>foo</li>� <li>bar</li>� </ul>
const Names = ({names}) => (� <ul id=”names”>� {names.map(name => <li>{name}</li>)}� </ul>�);