@gaoding/js-bridge
v1.0.6
Published
One of the ways for web interacts with app
Downloads
14
Keywords
Readme
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.