Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
fix: 修复支付宝自定义组件使用 component2 模式报错的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Darmody committed Dec 29, 2019
1 parent af61726 commit 109f904
Show file tree
Hide file tree
Showing 57 changed files with 1,636 additions and 784 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ function reduce(action) {
tree.lastActionId = action.id;

switch (action.type) {
case 'clear':
case 'init':
tree = {
root: {
children: [
action.payload[0].item,
]
},
lastActionId: -1,
};
return tree;
case 'clear':
tree.root = {
children: []
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<import-sjs name="helper" from="../../helper.sjs" />
<import-sjs name="helper" from="./helper.sjs" />
<template is="REMAX_TPL" data="{{tree: helper.reduce(action)}}" />

<template name="REMAX_TPL">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ function reduce(action) {
tree.lastActionId = action.id;

switch (action.type) {
case 'clear':
case 'init':
tree = {
root: {
children: [
action.payload[0].item,
]
},
lastActionId: -1,
};
return tree;
case 'clear':
tree.root = {
children: []
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<import-sjs name="helper" from="../helper.sjs" />
<import-sjs name="helper" from="./helper.sjs" />
<template is="REMAX_TPL" data="{{tree: helper.reduce(action)}}" />

<template name="REMAX_TPL">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ function reduce(action) {
tree.lastActionId = action.id;

switch (action.type) {
case 'clear':
case 'init':
tree = {
root: {
children: [
action.payload[0].item,
]
},
lastActionId: -1,
};
return tree;
case 'clear':
tree.root = {
children: []
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<import-sjs name="helper" from="../helper.sjs" />
<import-sjs name="helper" from="./helper.sjs" />
<template is="REMAX_TPL" data="{{tree: helper.reduce(action)}}" />

<template name="REMAX_TPL">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ function reduce(action) {
tree.lastActionId = action.id;

switch (action.type) {
case 'clear':
case 'init':
tree = {
root: {
children: [
action.payload[0].item,
]
},
lastActionId: -1,
};
return tree;
case 'clear':
tree.root = {
children: []
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<import-sjs name="helper" from="../helper.sjs" />
<import-sjs name="helper" from="./helper.sjs" />
<template is="REMAX_TPL" data="{{tree: helper.reduce(action)}}" />

<template name="REMAX_TPL">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ function reduce(action) {
tree.lastActionId = action.id;

switch (action.type) {
case 'clear':
case 'init':
tree = {
root: {
children: [
action.payload[0].item,
]
},
lastActionId: -1,
};
return tree;
case 'clear':
tree.root = {
children: []
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<wxs src="../helper.wxs" module="helper" /> <import src="../base.wxml"/> <template is="REMAX_TPL" data="{{tree: helper.reduce(action)}}" />
<wxs src="./helper.wxs" module="helper" /> <import src="../base.wxml"/> <template is="REMAX_TPL" data="{{tree: helper.reduce(action)}}" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
var tree = {
root: {
children: [],
},
lastActionId: -1
};

function reduce(action) {
if (action.id === tree.lastActionId) {
return tree;
}

tree.lastActionId = action.id;

switch (action.type) {
case 'init':
tree = {
root: {
children: [
action.payload[0].item,
]
},
lastActionId: -1,
};
return tree;
case 'clear':
tree.root = {
children: []
};
return tree;
case 'splice':
for (var i = 0; i < action.payload.length; i += 1) {
var value = get(tree, action.payload[i].path);
if (action.payload[i].item) {
value.splice(
action.payload[i].start,
action.payload[i].deleteCount,
action.payload[i].item
);
} else {
value.splice(action.payload[i].start, action.payload[i].deleteCount);
}
set(tree, action.payload[i].path, value);
}
return tree;
default:
return tree;
}
}

function getKey(key) {
var intKey = parseInt(key);
if (intKey.toString() === key) {
return intKey;
}
return key;
}

function set(obj, path, value) {
if (typeof path === 'string') {
path = path.split('.').map(getKey);
}

if (path.length === 1) {
obj[path[0]] = value;
}

var nextObj = obj;
for (var i = 0; i < path.length; i += 1) {
var currentPath = path[i];
var currentValue = nextObj[currentPath];

if (currentValue === void 0) {
//check if we assume an array
if (typeof path[i + 1] === 'number') {
nextObj[currentPath] = [];
} else {
nextObj[currentPath] = {};
}
}

if (i === path.length - 1) {
nextObj[currentPath] = value;
}

nextObj = nextObj[currentPath];
}
}

function get(obj, path) {
if (typeof path === 'string') {
path = path.split('.').map(getKey);
}

var nextObj = obj;
for (var i = 0; i < path.length; i += 1) {
var currentPath = path[i];
nextObj = nextObj[currentPath];
if (nextObj === void 0) {
if (currentPath === 'children') {
nextObj = [];
} else {
nextObj = {};
}
}
}

return nextObj;
}


export default {
reduce
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<import-sjs name="helper" from="../helper.sjs" />
<import-sjs name="helper" from="./helper.sjs" />
<template is="REMAX_TPL" data="{{tree: helper.reduce(action)}}" />

<template name="REMAX_TPL">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ function reduce(action) {
tree.lastActionId = action.id;

switch (action.type) {
case 'clear':
case 'init':
tree = {
root: {
children: [
action.payload[0].item,
]
},
lastActionId: -1,
};
return tree;
case 'clear':
tree.root = {
children: []
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<wxs src="../helper.wxs" module="helper" />
<wxs src="./helper.wxs" module="helper" />
<import src="../base.wxml"/>
<template is="REMAX_TPL" data="{{tree: helper.reduce(action)}}" />

This file was deleted.

Loading

0 comments on commit 109f904

Please sign in to comment.