@w6s/codash
v1.1.2
Published
A Cordova utility library.
Downloads
7
Readme
Codash
- 可配置,易用,轻松实现cordova promisify;
- 可添加拦截器,处理流程更方便;
- 接口可模拟,无需写两套同名方法;
- 提供常用方法,如绑定物理返回按钮,文件上传下载等。
使用 WorkPlus 扫一扫,查看在线 demo.
Docs
Install
npm install @w6s/codash --save
Usage
import { Cordova, deviceReady } from '@w6s/codash';
// 实例化,相关可用配置属性,请查看文档
const wp = new Cordova();
// 设置拦截器
wp.interceptors.before.use((config) => {
return config;
}, err => console.log(err));
wp.interceptors.after.use((response) => {
return response;
}, err => console.log(err));
// 创建promisify的cordova方法
const authHook = wp.addHook('WorkPlus_Auth');
const getUserTicket = authHook.create('getUserTicket');
const getAccessToken = wp.create('WorkPlus_Auth', 'getAccessToken');
// deviceReady 同样可以配置,具体请查看文档
deviceReady({ mock: false })
.then(() => Promise.all([getUserTicket(), getAccessToken()]))
.then((res) => {})
.catch((err) => {});