Giter Club home page Giter Club logo

react-native-timer-mixin's Introduction

react-native-timer-mixin

Fork of react-timer-mixin to add integration with the react-native InteractionManager.

Using bare setTimeout, setInterval, setImmediate, requestAnimationFrame and InteractionManager.runAfterInteractions calls is very dangerous because if you forget to cancel the request before the component is unmounted, you risk the callback throwing an exception. In the case of InteractionManager.createInteractionHandle you also want to be sure that the handle is cleaned up if for whatever reason the component is unmounted before that has a chance to occur.

If you include TimerMixin, then you can replace your calls to setTimeout(fn, 500) with this.setTimeout(fn, 500) (just prepend this.) and everything will be properly cleaned up for you.

Installation

Install the module directly from npm:

npm install react-native-timer-mixin

Example

var React = require('react');
var TimerMixin = require('react-timer-mixin');

var Component = React.createClass({
  mixins: [TimerMixin],
  componentDidMount() {
    this.setTimeout(() => {
      console.log('I do not leak!');
    }, 500);
    this.runAfterInteractions(() => {
      console.log('I also do not leak, unless you want me to ;)');
    });
  }
});

TODO

  • Mock out InteractionManager and add tests.

react-native-timer-mixin's People

Contributors

brentvatne avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-timer-mixin's Issues

Migrate to ES6

Just forked the react-timer-mixin repo directly and left it as it was, but we should migrate everything to ES6.

Update readme :)

A small typ0 in the example of readme
var TimerMixin = require('react-timer-mixin');

should be :)
var TimerMixin = require('react-native-timer-mixin');

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.