1.0.6 • Published 5 years ago

@gaoding/js-bridge v1.0.6

Weekly downloads
11
License
ISC
Repository
-
Last release
5 years ago

js-bridge

One of the ways for web interacts with app

Getting Started

Installation

npm install -S @gaoding/js-bridge

Usage

import { bridge, mockNative } from '../lib/bridge';
// MockNative is a function to config mock data, something params you hope app interface return to web.It's used in debug when you need in browser.

bridge.call('name', data)
.then(ret => {})
// Call function can be used to interact with app, for get data or awake user interface.
//Name is something like agreement or interface, then you can choose use data params or not.

bridge.registerOnce('name', callback);
// RegisterOnce is the way to register a fucntion, app can callbak through name when some operation success or failure.
// callback is a function include something you want to do when some operation success or failure.

Example

const mockData = {
    getUserInfo: {
        user_id: 13,
        name: 'Damon'
    }
}

mockNative(mockData); // config mock data

bridge.call('getUserInfo')
.then(ret => {
	console.log(ret) // { user_id: 13, name: 'Damon'} in browser debug
});
// What if run in dev environment, you'll get mokData finally.Otherwise, you'll get real data from app.
1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago