0.200.36 • Published 3 months ago

rflink-ble-api v0.200.36

Weekly downloads
-
License
ISC
Repository
bitbucket
Last release
3 months ago

RFLink BLE Library (for Redux-Saga and React-Redux)

You must have redux-saga and redux installed in your repository to use this.

This is the bluetooth library for Rockford Fosgate, containing all of the reducers, action-creators, and even sagas that will be used for all future projects around React and React Native.

Installation

Since this isn't backed up via npm (such backups require the use of a paid account), you will have to use an alternative repository.

Until the actual Ubuntu backend is setup, start by installing verdaccio.

After installing verdaccio, and cloning this repository, publish this application to your verdaccio.

To publish, start by running verdaccio. Then, cd into your repostiory that you want to publish (in this case, rflink-ble-api). After that, open up http://localhost:4873 in your browser (assuming you are using default port). After that, follow the instructions listed by verdaccio.

Now, just simply npm install rflink-ble-api -registry http://localhost:4873 inside of the project you wish to install rflink-ble-api in.

You have finished installing the npm installation--but you're not done. Follow the installation instructions for react-native-ble-plx before you proceed.

Now, you can import it just like usual!

Usage

There are a few more things to pay attention to outside of just importing the reducers and action creators though. If you are already familiar with setting up redux-saga, go ahead and import it normally. Otherwise, follow these directions.

First, we need to create a rootSaga object. You can see this example in example-rootsaga.js.

import { spawn, call, all } from 'redux-saga/effects'
import { bluetoothSaga } from 'rflink-ble-api'

export default function* rootSaga() {
  
  const sagas = [
    bluetoothSaga,
    // Rest of your sagas here...
  ]
  
  // Below is a function designed to handle errors in the sagas without crashing the whole application.
  yield all(sagas.map(saga=>
    spawn(function* () {
      while(true) {
        try {
          yield call(saga)
          break
        } catch(e) {
          console.log(e)
        }
      }
    })
  ))
}

This is the main saga that you have to import.

Now, you have to modify your reducers. If you already have pre-existing bluetooth components/mockups INSIDE of Redux, please remove those. More than likely, your dispatches will change as well, so keep that in mind.

This is an example of how you would import rflink reducers into your root reducer:

import { combineReducers } from 'redux'
import { deviceReducer } from 'rflink-ble-api'
import { bluetoothReducer } from 'rflink-ble-api'

export default rootReducer = combineReducers({
  device: deviceReducer,
  bluetooth: bluetoothReducer,
})

Imports

You can view every single thing you can import via index.js.

Implementation

Actions

Inside of bluetooth-action.js, and bluetooth-reducers.js, you may have noticed that some of these are far too simple to possibly be working.

First, the saga in bluetooth-saga is responsible for a large majority of the calls. What happens is that the saga takes in certain dispatch functions, and applies a middleman function to them upon receiving this dispatch function.

Our design decision between this was a tradeoff between performance (as this would be asynchronous) vs. code maintainability. As you can see, we have chosen code maintainbility (and keeping such design abstracted from us while coding) in order to facilitate more modular, and cleaner code.

Sagas

Further information can be found on redux-saga's own personal documentation, but it receives/listens for a bluetooth-action, and then calls a function of its own. This function is typically inherited from APIs.

API

We are currently using Polidea's own BLE implementation for React-Native. There's a lot going on here. First, we have event emitters. All it really is a callback middleman. Once an event is called, then the callback function will be called as well.

0.200.36

3 months ago

0.200.35

3 months ago

0.200.34

3 months ago

0.200.33

3 months ago

0.200.32

3 months ago

0.200.31

3 months ago

0.200.30

3 months ago

0.200.29

3 months ago

0.200.28

3 months ago

0.200.26

4 months ago

0.200.25

4 months ago

0.200.24

4 months ago

0.200.23

4 months ago

0.200.22

5 months ago

0.200.21

5 months ago

0.200.20

5 months ago

0.200.19

5 months ago

0.200.18

5 months ago

0.200.17

5 months ago

0.200.16

5 months ago

0.200.15

5 months ago

0.200.14

5 months ago

0.200.13

6 months ago

0.200.12

6 months ago

0.200.11

6 months ago

0.200.10

6 months ago

0.200.9

6 months ago

0.200.8

6 months ago

0.200.7

6 months ago

0.200.6

6 months ago

0.200.5

6 months ago

0.200.4

6 months ago

0.200.3

6 months ago

0.200.2

6 months ago

0.200.1

6 months ago

0.200.0

6 months ago