Skip to content

Instantly share code, notes, and snippets.

View vldvel's full-sized avatar

Vlad vldvel

  • Amsterdam
View GitHub Profile
@vldvel
vldvel / PullToUpdate.js
Created December 17, 2018 08:56
Using Swiper.js
import * as React from 'react';
import { Loader } from 'path-to-loader';
import { Swiper } from 'path-to-swiper';
class PullToUpdate extends React.PureComponent {
state = {
translate: 0
};
rootNode = null;
@vldvel
vldvel / setInterval-in-componentdidMount.js
Last active October 10, 2020 16:54
setInterval in componentdidMount
class NewMessages extends Rect.Component {
updateInterval;
componentDidMount() {
this.updateInterval = setInterval(() => {
this.props.getNewMessages();
}, 500);
}
componentWillUnmount() {
@vldvel
vldvel / setTimeout-in-componentDidMount.js
Created February 7, 2019 06:23
setTimeout in componentDidMount
class NewMessages extends React.PureComponent {
updateTimeout;
componentDidMount() {
this.updateMessages();
}
updateMessages = async () => {
// thunk
await this.props.getNewMessages(); // waiting for request
@vldvel
vldvel / initActions-in-root.js
Last active February 7, 2019 06:47
initActions in root
export const initActions = async dispatch => {
let updateTimeout;
updateMessages = async () => {
await dispatch(getNewMessages());
updateTimeout = setTimeout(updateMessages, 500);
}
updateMessages();
}
@vldvel
vldvel / update-in-middleware.js
Last active February 7, 2019 06:58
update in middleware
const updateMessagesMiddleware = ({ dispatch }) => next => {
const updateMessages = async () => {
await getNewMessages()(dispatch);
setTimeout(updateMessages, 500);
};
updateMessages();
return action => next(action);
};
@vldvel
vldvel / add-middleware-to-store.js
Created February 7, 2019 07:03
add middleware to store
const store = createStore(
rootReducer,
compose(applyMiddleware(/** other middlewares */, updateMessagesMiddleware))
);
const EnumStatus = {
LOADED: 'LOADED',
LOADING: 'LOADING',
FAILED: 'FAILED'
}
const state = {
subState_1: {
data: any,
status: EnumStatus
@vldvel
vldvel / WeatherAppSetInterval.js
Created June 11, 2020 06:31
Setting the interval in the WeatherApp component to constantly pull weather data.
class WeatherApp extends Rect.Component {
updateInterval;
componentDidMount() {
this.updateInterval = setInterval(() => {
this.props.getWeatherData();
}, 1000 * 30); // 30 seconds
}
componentWillUnmount() {
@vldvel
vldvel / WeatherAppSetTimeout.js
Last active June 12, 2020 06:33
Setting the timeout in the WeatherApp component to constantly pull weather data.
class WeatherApp extends React.Component {
updateTimeout;
componentDidMount() {
this.getWeatherData();
}
getWeatherData = async () => {
await this.props.getWeatherData();
@vldvel
vldvel / WeatherAppInitActions.js
Created June 12, 2020 06:34
Creating inital actions in the WeatherApp component to constantly pull weather data.
export const initActions = async dispatch => {
let updateTimeout;
getWeatherDataTimedout = async () => {
await dispatch(getWeatherData());
updateTimeout = setTimeout(getWeatherDataTimedout, 30 * 1000);
}
/** Initialize any other actions */