Skip to content

Commit

Permalink
build uni runtime(refactor previewImage)
Browse files Browse the repository at this point in the history
  • Loading branch information
fxy060608 committed May 9, 2019
1 parent bc23156 commit 1198bbd
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 159 deletions.
68 changes: 33 additions & 35 deletions packages/uni-mp-baidu/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,33 +144,39 @@ function upx2px (number, newDeviceWidth) {
return number < 0 ? -result : result
}

function normalize (fromArgs) {
let currentIndex = parseInt(fromArgs.current);
if (isNaN(currentIndex)) {
return
}
const urls = fromArgs.urls;
if (!Array.isArray(urls)) {
return
}
const len = urls.length;
if (!len) {
return
}
if (currentIndex < 0) {
currentIndex = 0;
} else if (currentIndex >= len) {
currentIndex = len - 1;
}
if (currentIndex > 0) {
fromArgs.current = urls[currentIndex];
fromArgs.urls = urls.filter(
(item, index) => index < currentIndex ? item !== urls[currentIndex] : true
);
} else {
fromArgs.current = urls[0];
var previewImage = {
args (fromArgs) {
let currentIndex = parseInt(fromArgs.current);
if (isNaN(currentIndex)) {
return
}
const urls = fromArgs.urls;
if (!Array.isArray(urls)) {
return
}
const len = urls.length;
if (!len) {
return
}
if (currentIndex < 0) {
currentIndex = 0;
} else if (currentIndex >= len) {
currentIndex = len - 1;
}
if (currentIndex > 0) {
fromArgs.current = urls[currentIndex];
fromArgs.urls = urls.filter(
(item, index) => index < currentIndex ? item !== urls[currentIndex] : true
);
} else {
fromArgs.current = urls[0];
}
return {
indicator: false,
loop: false
}
}
}
};

// 不支持的 API 列表
const todos = [
Expand Down Expand Up @@ -232,15 +238,7 @@ const protocols = {
method: false
}
},
previewImage: {
args (fromArgs) {
normalize(fromArgs);
return {
indicator: false,
loop: false
}
}
},
previewImage,
getRecorderManager: {
returnValue (fromRet) {
fromRet.onFrameRecorded = createTodoMethod('RecorderManager', 'onFrameRecorded');
Expand Down
2 changes: 1 addition & 1 deletion packages/uni-mp-baidu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dcloudio/uni-mp-baidu",
"version": "0.0.829",
"version": "0.0.830",
"description": "uni-app mp-baidu",
"main": "dist/index.js",
"scripts": {
Expand Down
68 changes: 33 additions & 35 deletions packages/uni-mp-toutiao/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,33 +144,39 @@ function upx2px (number, newDeviceWidth) {
return number < 0 ? -result : result
}

function normalize (fromArgs) {
let currentIndex = parseInt(fromArgs.current);
if (isNaN(currentIndex)) {
return
}
const urls = fromArgs.urls;
if (!Array.isArray(urls)) {
return
}
const len = urls.length;
if (!len) {
return
}
if (currentIndex < 0) {
currentIndex = 0;
} else if (currentIndex >= len) {
currentIndex = len - 1;
}
if (currentIndex > 0) {
fromArgs.current = urls[currentIndex];
fromArgs.urls = urls.filter(
(item, index) => index < currentIndex ? item !== urls[currentIndex] : true
);
} else {
fromArgs.current = urls[0];
var previewImage = {
args (fromArgs) {
let currentIndex = parseInt(fromArgs.current);
if (isNaN(currentIndex)) {
return
}
const urls = fromArgs.urls;
if (!Array.isArray(urls)) {
return
}
const len = urls.length;
if (!len) {
return
}
if (currentIndex < 0) {
currentIndex = 0;
} else if (currentIndex >= len) {
currentIndex = len - 1;
}
if (currentIndex > 0) {
fromArgs.current = urls[currentIndex];
fromArgs.urls = urls.filter(
(item, index) => index < currentIndex ? item !== urls[currentIndex] : true
);
} else {
fromArgs.current = urls[0];
}
return {
indicator: false,
loop: false
}
}
}
};

// 不支持的 API 列表
const todos = [
Expand Down Expand Up @@ -265,15 +271,7 @@ const protocols = {
sizeType: false
}
},
previewImage: {
args (fromArgs) {
normalize(fromArgs);
return {
indicator: false,
loop: false
}
}
},
previewImage,
connectSocket: {
args: {
method: false
Expand Down
2 changes: 1 addition & 1 deletion packages/uni-mp-toutiao/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dcloudio/uni-mp-toutiao",
"version": "0.0.327",
"version": "0.0.328",
"description": "uni-app mp-toutiao",
"main": "dist/index.js",
"scripts": {
Expand Down
62 changes: 33 additions & 29 deletions packages/uni-mp-weixin/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,38 +144,42 @@ function upx2px (number, newDeviceWidth) {
return number < 0 ? -result : result
}

function normalize (fromArgs) {
let currentIndex = parseInt(fromArgs.current);
if (isNaN(currentIndex)) {
return
}
const urls = fromArgs.urls;
if (!Array.isArray(urls)) {
return
}
const len = urls.length;
if (!len) {
return
}
if (currentIndex < 0) {
currentIndex = 0;
} else if (currentIndex >= len) {
currentIndex = len - 1;
}
if (currentIndex > 0) {
fromArgs.current = urls[currentIndex];
fromArgs.urls = urls.filter(
(item, index) => index < currentIndex ? item !== urls[currentIndex] : true
);
} else {
fromArgs.current = urls[0];
var previewImage = {
args (fromArgs) {
let currentIndex = parseInt(fromArgs.current);
if (isNaN(currentIndex)) {
return
}
const urls = fromArgs.urls;
if (!Array.isArray(urls)) {
return
}
const len = urls.length;
if (!len) {
return
}
if (currentIndex < 0) {
currentIndex = 0;
} else if (currentIndex >= len) {
currentIndex = len - 1;
}
if (currentIndex > 0) {
fromArgs.current = urls[currentIndex];
fromArgs.urls = urls.filter(
(item, index) => index < currentIndex ? item !== urls[currentIndex] : true
);
} else {
fromArgs.current = urls[0];
}
return {
indicator: false,
loop: false
}
}
}
};

const protocols = {
previewImage: {
args: normalize
}
previewImage
};
const todos = [];
const canIUses = [];
Expand Down
2 changes: 1 addition & 1 deletion packages/uni-mp-weixin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dcloudio/uni-mp-weixin",
"version": "0.0.951",
"version": "0.0.952",
"description": "uni-app mp-weixin",
"main": "dist/index.js",
"scripts": {
Expand Down
12 changes: 2 additions & 10 deletions src/platforms/mp-baidu/service/api/protocols.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import normalizePreviewImageArgs from '../../../mp-weixin/helpers/normalize-preview-image-args'
import previewImage from '../../../mp-weixin/helpers/normalize-preview-image'
// 不支持的 API 列表
const todos = [
'hideKeyboard',
Expand Down Expand Up @@ -59,15 +59,7 @@ const protocols = {
method: false
}
},
previewImage: {
args (fromArgs) {
normalizePreviewImageArgs(fromArgs)
return {
indicator: false,
loop: false
}
}
},
previewImage,
getRecorderManager: {
returnValue (fromRet) {
fromRet.onFrameRecorded = createTodoMethod('RecorderManager', 'onFrameRecorded')
Expand Down
12 changes: 2 additions & 10 deletions src/platforms/mp-toutiao/service/api/protocols.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import normalizePreviewImageArgs from '../../../mp-weixin/helpers/normalize-preview-image-args'
import previewImage from '../../../mp-weixin/helpers/normalize-preview-image'

// 不支持的 API 列表
const todos = [
Expand Down Expand Up @@ -93,15 +93,7 @@ const protocols = {
sizeType: false
}
},
previewImage: {
args (fromArgs) {
normalizePreviewImageArgs(fromArgs)
return {
indicator: false,
loop: false
}
}
},
previewImage,
connectSocket: {
args: {
method: false
Expand Down
27 changes: 0 additions & 27 deletions src/platforms/mp-weixin/helpers/normalize-preview-image-args.js

This file was deleted.

33 changes: 33 additions & 0 deletions src/platforms/mp-weixin/helpers/normalize-preview-image.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export default {
args (fromArgs) {
let currentIndex = parseInt(fromArgs.current)
if (isNaN(currentIndex)) {
return
}
const urls = fromArgs.urls
if (!Array.isArray(urls)) {
return
}
const len = urls.length
if (!len) {
return
}
if (currentIndex < 0) {
currentIndex = 0
} else if (currentIndex >= len) {
currentIndex = len - 1
}
if (currentIndex > 0) {
fromArgs.current = urls[currentIndex]
fromArgs.urls = urls.filter(
(item, index) => index < currentIndex ? item !== urls[currentIndex] : true
)
} else {
fromArgs.current = urls[0]
}
return {
indicator: false,
loop: false
}
}
}
12 changes: 2 additions & 10 deletions src/platforms/mp-weixin/service/api/protocols.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import normalizePreviewImageArgs from '../../helpers/normalize-preview-image-args'
import previewImage from '../../helpers/normalize-preview-image'
export const protocols = {
previewImage: {
args (fromArgs) {
normalizePreviewImageArgs(fromArgs)
return {
indicator: false,
loop: false
}
}
}
previewImage
}
export const todos = []
export const canIUses = []

0 comments on commit 1198bbd

Please sign in to comment.