RxJS and Redux Observable have opened the door to the reactive programming paradigm in our frontend frameworks. Let’s take full advantage and “automate” many of the processes we do when requesting data from external APIs.
- Intro
- About Me
function ellipsis(str, maxWords = 2) { | |
let i = 0; | |
let spaces = 0; | |
let result = ""; | |
while (spaces < maxWords && i < str.length) { | |
const c = str.charAt(i++); | |
if (c == " ") ++spaces; | |
result += c; | |
} |
export default function send(source$) { | |
reutrn source$.subscribe(({ fn }) => fn()); | |
} |
/* | |
* File Name: clock-component-reducer.js | |
* The reducer always returns a new object so that Redux can compare | |
* the value of its current state to whatever the reducer returns | |
*/ | |
export function timeReducer(state = {}, action) { | |
// Only evaluate the actions that are relavent to this componentReducer | |
switch (action.type) { | |
case 'GET_TIME': |
/* | |
* File Name: clock-component.jsx | |
* The fetch is now replaces by an action creator call | |
*/ | |
componentDidMount() { | |
// Call the action creator | |
this.props.getTime(); | |
} |
/* | |
* File Name: clock-component-action.js | |
* A function that creates an action with the current time | |
*/ | |
import moment from 'moment'; | |
// Defining a constant that should never change! | |
const GET_TIME = 'GET_TIME'; | |
export function getTime() { |
/* | |
* Filename: clock-component.jsx | |
* A snippet from a React component showing the component connecting to the Redux store | |
*/ | |
// `Connect` is the component listening to the store for changes | |
export default connect(ClockComponent); |
".source.speck": | |
Log: | |
prefix: "sclog" | |
body: "console.log(`${1} : ${${1}}`);" |
<h1>It's A Button! 😬</h1> | |
<button class="mui-button"> | |
<div class="ripple"></div> | |
<p>click me!</p> | |
</button> |
#A Beginners Guide to Building a Website like a Programmer