GithubHelp home page GithubHelp logo

palerdot / react-native-workers Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fabriciovergara/react-native-workers

0.0 3.0 0.0 618 KB

Do heavy data process outside of your UI JS thread.

License: Apache License 2.0

Java 58.13% JavaScript 14.49% Python 4.55% Swift 3.29% Objective-C 19.55%

react-native-workers's Introduction

react-native-workers (RN 0.43^)

Do heavy data process outside of your UI JS thread.

Before using this kind of solution you should check if InteractionManager.runAfterInteractions is not enough for your needs, because creating a aditional worker can considerably increase app memory usage.

I mostly use this library for a personal project, that wrap a native database with a graphql api. So the updates may follow my needs, but any PR is welcome.

Automatic Instalation

npm install --save rn-workers
react-native link rn-workers

Or Install manually

Prepare your project following this SETUP GUIDE

App side

    //index.ios.js 
    import { Worker } from 'rn-workers'

    export default class rnapp extends React.Component {

        componentDidMount () {
            //Create using default worker port (8082)
            this.worker = new Worker();
            
            //Create worker pointing to custom one
            this.worker2 = new Worker(8083);
            
            
            //Add listener to receve messages
            this.worker.onmessage = message => this.setState({
                 text: message,
                 count: this.state.count + 1
            });

            //Send message to worker (Only strings is allowed for now)
            this.worker.postMessage("Hey Worker!")
        }

        componentWillUnmount () {
            //Terminate worker
            this.worker.terminate();
        }
        
        (...)
     }

Worker side

    //index.worker.js
    import { WorkerService } from 'rn-workers'
    
    const worker = new WorkerService();
    worker.onmessage = message => {
        //Reply the message back to app
        worker.postMessage("Hello from the other side (" + message + ")")
    };

Aditional Information

License

Cancer GPL ..... just kindind, its Apache 2.0

react-native-workers's People

Contributors

guns2410 avatar

Watchers

James Cloos avatar Arun Kumar avatar  avatar

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.