Skip to content

Instantly share code, notes, and snippets.

View OlivierJM's full-sized avatar

ojm OlivierJM

View GitHub Profile
@OlivierJM
OlivierJM / introrx.md
Created December 20, 2018 17:45 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
const debounce = (func, delay) => {
let inDebounce
return function(...args){ // curry the the other arguments
// const args = argumets
const context = this
clearTimeout(inDebounce)
inDebounce = setTimeout(() => func.apply(context, args), delay)
const debounce = (func, delay) => {
let inDebounce
return function(...args){ // curry the the other arguments
// const args = argumets
const context = this
clearTimeout(inDebounce)
inDebounce = setTimeout(() => func.apply(context, args), delay)

Contributing

When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.

Please note we have a code of conduct, please follow it in all your interactions with the project.

Pull Request Process

  1. Ensure that the project is building successfully
// class component with destructuring
class UserSection extends React.Component {
render(){
const { user, isActive } = this.props;
return(
<div>
<p>{user.name}</p> <span>{isActive ? 'active' : 'offline'}</span>
</div>
)
}
// functional component with partial destructuring
const UserSection = ({ user, isActive }) => (
<div>
<p>{user.name}</p> <span> {isActive ? 'active' : 'offline'} </span>
</div>
);
// functional component with no destructuring
const UserSection = props => (
@OlivierJM
OlivierJM / asyncfetchData.js
Last active August 7, 2018 15:04
use the async and await with axios on multiple request with multiple promises
getRemoteData = async () => {
try {
const coursePromise = axios('http://x.x.x.x/api/course/');
const topicPromise = axios('http://x.x.x.x/api/topic/');
const [ courses, topics ] = await Promise.all(coursePromise, topicPromise]);
this.setState({
courses: courses.data.data,
topics: topics.data.data,
loading: false,
});
function getData() {
HTTP.call('GET', 'https://jsonplaceholder.typicode.com/posts', (err, res) => {
if(err){
console.log(err);
} else {
console.log(res);
}
});
console.log('Going to grab data');
}
function getData() {
HTTP.call('GET', 'https://jsonplaceholder.typicode.com/posts');
console.log('Going to grab data');
}
function calculateExactAge(bornYear=1995, currentYear=2018){
console.log(currentYear - bornYear);
}
calculateExactAge(); // 23
calculateExactAge(2010, 2020); // 10