Skip to content

Commit

Permalink
fix(wx-react): 修复StyleSheet flatten
Browse files Browse the repository at this point in the history
  • Loading branch information
ykforerlang committed Nov 5, 2019
1 parent 76b0c70 commit e334318
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/wx-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@areslabs/wx-react",
"version": "1.0.32",
"version": "1.0.33",
"description": "微信版本的React",
"files": [
"miniprogram_dist",
Expand Down
23 changes: 10 additions & 13 deletions packages/wx-react/src/tackleWithStyleObj.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,33 +280,30 @@ function parseObj(obj) {
return out;
}

function flattenArray(arr, ans = {}) {
if (!Array.isArray(arr)) return arr

function flattenArray(arr, ans = []) {
if (!Array.isArray(arr)) return arr;
for (let m in arr) {
if (!Array.isArray(arr[m])) {
Object.assign(ans, arr[m])
ans.push(arr[m]);
} else {
flattenArray(arr[m], ans)
flattenArray(arr[m], ans);
}
}
return ans
return ans;
}


/**
* the inverse process of tackleWithStyleObj
* @param str
*/
export function flattenStyle(str) {

if (Array.isArray(str)) {
return flattenArray(str)
export function flattenStyle(fstyle) {
let str = fstyle
if (typeof fstyle !== 'string') {
// 可能是数组,可能是字符串,可能是其组合
str = tackleWithStyleObj(fstyle)
}

if (typeof str === 'object') {
return str
}

const array = str.split(';').filter(i => i)
const obj = {}
Expand Down

0 comments on commit e334318

Please sign in to comment.