Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持 Mock.mock( rurl, [rtype], function( options ) ) 的回调函数返回 Promise 对象 #236

Open
wants to merge 2 commits into
base: refactoring
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
registry=https://registry.npm.taobao.org
disturl=https://npm.taobao.org/dist
electron_mirror=http://cdn.npm.taobao.org/dist/electron/
node_inspector_cdnurl=https://npm.taobao.org/mirrors/node-inspector
sass_binary_site=http://cdn.npm.taobao.org/dist/node-sass
10 changes: 5 additions & 5 deletions dist/mock-min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/mock-min.js.map

Large diffs are not rendered by default.

144 changes: 80 additions & 64 deletions dist/mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ return /******/ (function(modules) { // webpackBootstrap
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {

/* global require, module, window */
var Handler = __webpack_require__(1)
Expand Down Expand Up @@ -122,9 +122,9 @@ return /******/ (function(modules) { // webpackBootstrap

module.exports = Mock

/***/ },
/***/ }),
/* 1 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {

/*
## Handler
Expand Down Expand Up @@ -667,9 +667,9 @@ return /******/ (function(modules) { // webpackBootstrap

module.exports = Handler

/***/ },
/***/ }),
/* 2 */
/***/ function(module, exports) {
/***/ (function(module, exports) {

/*
## Constant
Expand Down Expand Up @@ -705,9 +705,9 @@ return /******/ (function(modules) { // webpackBootstrap
// RE_KEY: /^key$/
}

/***/ },
/***/ }),
/* 3 */
/***/ function(module, exports) {
/***/ (function(module, exports) {

/*
## Utilities
Expand Down Expand Up @@ -836,9 +836,9 @@ return /******/ (function(modules) { // webpackBootstrap

module.exports = Util

/***/ },
/***/ }),
/* 4 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {

/*
## Parser
Expand Down Expand Up @@ -912,9 +912,9 @@ return /******/ (function(modules) { // webpackBootstrap
}
}

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

/*
## Mock.Random
Expand All @@ -941,9 +941,9 @@ return /******/ (function(modules) { // webpackBootstrap

module.exports = Random

/***/ },
/***/ }),
/* 6 */
/***/ function(module, exports) {
/***/ (function(module, exports) {

/*
## Basics
Expand Down Expand Up @@ -1072,9 +1072,9 @@ return /******/ (function(modules) { // webpackBootstrap
}
}

/***/ },
/***/ }),
/* 7 */
/***/ function(module, exports) {
/***/ (function(module, exports) {

/*
## Date
Expand Down Expand Up @@ -1218,9 +1218,9 @@ return /******/ (function(modules) { // webpackBootstrap
}
}

/***/ },
/***/ }),
/* 8 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {

/* WEBPACK VAR INJECTION */(function(module) {/* global document */
/*
Expand Down Expand Up @@ -1506,9 +1506,9 @@ return /******/ (function(modules) { // webpackBootstrap
}
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(9)(module)))

/***/ },
/***/ }),
/* 9 */
/***/ function(module, exports) {
/***/ (function(module, exports) {

module.exports = function(module) {
if(!module.webpackPolyfill) {
Expand All @@ -1522,9 +1522,9 @@ return /******/ (function(modules) { // webpackBootstrap
}


/***/ },
/***/ }),
/* 10 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {

/*
## Color
Expand Down Expand Up @@ -1664,9 +1664,9 @@ return /******/ (function(modules) { // webpackBootstrap
}
}

/***/ },
/***/ }),
/* 11 */
/***/ function(module, exports) {
/***/ (function(module, exports) {

/*
## Color Convert
Expand Down Expand Up @@ -1846,9 +1846,9 @@ return /******/ (function(modules) { // webpackBootstrap
}
}

/***/ },
/***/ }),
/* 12 */
/***/ function(module, exports) {
/***/ (function(module, exports) {

/*
## Color 字典数据
Expand Down Expand Up @@ -1927,9 +1927,9 @@ return /******/ (function(modules) { // webpackBootstrap
}
}

/***/ },
/***/ }),
/* 13 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {

/*
## Text
Expand Down Expand Up @@ -2053,9 +2053,9 @@ return /******/ (function(modules) { // webpackBootstrap
}
}

/***/ },
/***/ }),
/* 14 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {

/*
## Helpers
Expand Down Expand Up @@ -2174,9 +2174,9 @@ return /******/ (function(modules) { // webpackBootstrap
}
}

/***/ },
/***/ }),
/* 15 */
/***/ function(module, exports) {
/***/ (function(module, exports) {

/*
## Name
Expand Down Expand Up @@ -2266,9 +2266,9 @@ return /******/ (function(modules) { // webpackBootstrap
}
}

/***/ },
/***/ }),
/* 16 */
/***/ function(module, exports) {
/***/ (function(module, exports) {

/*
## Web
Expand Down Expand Up @@ -2347,9 +2347,9 @@ return /******/ (function(modules) { // webpackBootstrap
}
}

/***/ },
/***/ }),
/* 17 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {

/*
## Address
Expand Down Expand Up @@ -2399,9 +2399,9 @@ return /******/ (function(modules) { // webpackBootstrap
// state: function() {},
}

/***/ },
/***/ }),
/* 18 */
/***/ function(module, exports) {
/***/ (function(module, exports) {

/*
## Address 字典数据
Expand Down Expand Up @@ -6472,9 +6472,9 @@ return /******/ (function(modules) { // webpackBootstrap

module.exports = DICT_FIXED

/***/ },
/***/ }),
/* 19 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {

/*
## Miscellaneous
Expand Down Expand Up @@ -6582,9 +6582,9 @@ return /******/ (function(modules) { // webpackBootstrap
}
}

/***/ },
/***/ }),
/* 20 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {

var Parser = __webpack_require__(21)
var Handler = __webpack_require__(22)
Expand All @@ -6593,9 +6593,9 @@ return /******/ (function(modules) { // webpackBootstrap
Handler: Handler
}

/***/ },
/***/ }),
/* 21 */
/***/ function(module, exports) {
/***/ (function(module, exports) {

// https://github.com/nuysoft/regexp
// forked from https://github.com/ForbesLindesay/regexp
Expand Down Expand Up @@ -7168,9 +7168,9 @@ return /******/ (function(modules) { // webpackBootstrap

module.exports = parser

/***/ },
/***/ }),
/* 22 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {

/*
## RegExp Handler
Expand Down Expand Up @@ -7565,15 +7565,15 @@ return /******/ (function(modules) { // webpackBootstrap

module.exports = Handler

/***/ },
/***/ }),
/* 23 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {

module.exports = __webpack_require__(24)

/***/ },
/***/ }),
/* 24 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {

/*
## toJSONSchema
Expand Down Expand Up @@ -7624,15 +7624,15 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = toJSONSchema


/***/ },
/***/ }),
/* 25 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {

module.exports = __webpack_require__(26)

/***/ },
/***/ }),
/* 26 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {

/*
## valid(template, data)
Expand Down Expand Up @@ -8080,15 +8080,15 @@ return /******/ (function(modules) { // webpackBootstrap

module.exports = valid

/***/ },
/***/ }),
/* 27 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {

module.exports = __webpack_require__(28)

/***/ },
/***/ }),
/* 28 */
/***/ function(module, exports, __webpack_require__) {
/***/ (function(module, exports, __webpack_require__) {

/* global window, document, location, Event, setTimeout */
/*
Expand Down Expand Up @@ -8352,6 +8352,9 @@ return /******/ (function(modules) { // webpackBootstrap
// Initiates the request.
send: function send(data) {
var that = this
var response
var compiler

this.custom.options.body = data

// 原生 XHR
Expand All @@ -8368,8 +8371,23 @@ return /******/ (function(modules) { // webpackBootstrap
// loadstart The fetch initiates.
this.dispatchEvent(new Event('loadstart' /*, false, false, this*/ ))

if (this.custom.async) setTimeout(done, this.custom.timeout) // 异步
else done() // 同步
compiler = convert(that.custom.template, that.custom.options)

if (typeof compiler.then === 'function') {
// Promise
compiler.then(function (data) {
response = data
done()
})
} else if (this.custom.async) {
// 异步
response = compiler
setTimeout(done, this.custom.timeout)
} else {
// 同步
response = compiler
done()
}

function done() {
that.readyState = MockXMLHttpRequest.HEADERS_RECEIVED
Expand All @@ -8381,10 +8399,7 @@ return /******/ (function(modules) { // webpackBootstrap
that.statusText = HTTP_STATUS_CODES[200]

// fix #92 #93 by @qddegtya
that.response = that.responseText = JSON.stringify(
convert(that.custom.template, that.custom.options),
null, 4
)
that.response = that.responseText = JSON.stringify(response, null, 4)

that.readyState = MockXMLHttpRequest.DONE
that.dispatchEvent(new Event('readystatechange' /*, false, false, that*/ ))
Expand Down Expand Up @@ -8533,7 +8548,8 @@ return /******/ (function(modules) { // webpackBootstrap

module.exports = MockXMLHttpRequest

/***/ }

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