Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
duwen committed Sep 17, 2017
1 parent 3d60c15 commit e67876f
Show file tree
Hide file tree
Showing 26 changed files with 655 additions and 794 deletions.
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,39 @@ fly.get()....



## 下面的适配器在京锣密鼓的开发中....
## Adapter

接口签名如下:

```javascript
function (request, responseCallBack)
```

**request**: 请求对象,由engine传给adapter,结构如下:

```javascript
{
method:"",//请求方法, GET 、POST ...
headers:{},//请求头
url:"",//请求地址
data:""//请求数据,GET请求时为null
}
```

**responseCallBack(response)**: 响应回调

请求结束时调用此函数,通知engine, response结构如下:

```
{
responseText: '{"aa":5}',//响应内容,为字符串
statusCode: 200,// http 状态码,发生异常时,值为0
errMsg:"", //错误信息
headers: {}//响应头
}
```



### 其它javascript bridge的 adapter

Expand Down
19 changes: 14 additions & 5 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@
var path = require('path');
var webpack = require('webpack');
var env=process.argv[2]||"dev"

var entry={
"engine": "./src/engine.js",
"fly": "./src/fly.js",
"adapter/dsbridge":"./src/adapter/dsbridge.js",
"adapter/webviewjsbridge":"./src/adapter/webviewjsbridge.js",
}
var output = {
path: path.resolve("./dist"),
filename: "[name].js"
}

var plugins=[];
if (env !== "dev") {
output.filename = "[name].min.js"
Expand All @@ -21,15 +29,16 @@ if (env !== "dev") {
output.filename = "[name].umd.min.js"
}
}else{
Object.assign(entry,{
"adapter/node":"./src/adapter/node.js",
"../demon/dist/test": "./demon/test.js",
})
output.libraryTarget = "umd"

}

var config= {
entry: {
"engine": "./src/engine.js",
"fly": "./src/fly.js",
"test": "./demon/test.js"
},
entry: entry,
output: output,
module: {
rules: [
Expand Down
2 changes: 1 addition & 1 deletion demon/demoCommonJs.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=0.5,user-scalable=no"/>
<script src="../dist/test.js"></script>
<script src="dist/test.js"></script>
<!--<script src="https://cdn.bootcss.com/axios/0.16.2/axios.js"></script>-->

</head>
Expand Down
39 changes: 39 additions & 0 deletions demon/engine.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>fly ajax-engine</title>
<meta name="viewport" content="width=device-width,initial-scale=0.5,user-scalable=no"/>
<script src="../dist/fly.min.js"></script>
<script src="../dist/engine.min.js"></script>
<script src="https://cdn.bootcss.com/axios/0.16.2/axios.js"></script>
<script>
var log=console.log;
AjaxEngine.setAdapter(function (request,responseCallback) {
console.log(request)
responseCallback({
statusCode:0,
errMsg:"exception"
})
})
fly.engine=AjaxEngine;
XMLHttpRequest=AjaxEngine
//
// fly.post("../package.json",{aa:8,bb:9,tt:{xx:5}}).then((d) => {
// console.log("get result:",d)
// }).catch((e) => console.log("error", e))

// var formData = new FormData();
// formData.append('username', 'Chris');
// axios.post("../package.json",formData).then(log).catch(log)
// fly.post("../package.json",formData).then(log).catch(log)
fly.post("../package.json")
axios.post("../package.json")


</script>
</head>
<body>

</body>
</html>
109 changes: 109 additions & 0 deletions dist/adapter/dsbridge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else {
var a = factory();
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
}
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // identity function for calling harmony imports with the correct context
/******/ __webpack_require__.i = function(value) { return value; };
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 1);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */,
/* 1 */
/***/ (function(module, exports) {

function KEEP(_,cb){cb();}
"use strict";

//确保dsBridge初始化
window._dsbridge && _dsbridge.init();
var adapter;
if (window.dsBridge) {
adapter = function adapter(request, responseCallBack) {
dsBridge.call("onAjaxRequest", request, function (responseData) {
responseCallBack(JSON.parse(responseData));
});
};
} else {
console.error("dsBridge is not exist!");
}

//build环境定义全局变量
;

KEEP("!build", function () {
module.exports = adapter;
});

/***/ })
/******/ ]);
});
1 change: 1 addition & 0 deletions dist/adapter/dsbridge.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/adapter/dsbridge.umd.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 94 additions & 0 deletions dist/adapter/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else {
var a = factory();
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
}
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // identity function for calling harmony imports with the correct context
/******/ __webpack_require__.i = function(value) { return value; };
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 5);
/******/ })
/************************************************************************/
/******/ ({

/***/ 5:
/***/ (function(module, exports, __webpack_require__) {

"use strict";


exports = function exports(request, responseCallBack) {
//待实现
};

/***/ })

/******/ });
});
Loading

0 comments on commit e67876f

Please sign in to comment.