jiaqingjiayi-xiaochengxu/甲情_甲意/miniprogram/node_modules/antd-mini/less/mixins/computed.js

39 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-11-10 07:01:22 +00:00
/* eslint-disable @typescript-eslint/no-explicit-any */
2024-12-01 11:56:54 +00:00
import deepEqual from 'fast-deep-equal';
import { getValueFromProps } from '../_util/simply';
2024-11-10 07:01:22 +00:00
function computedData() {
var _this = this;
2024-12-01 11:56:54 +00:00
var nextData = this.computed(getValueFromProps(this));
2024-11-10 07:01:22 +00:00
// 浅比较就行了
var changedData = Object.keys(nextData).reduce(function (prev, item) {
// 移除 _ $ 开头的保留 props
if (item[0] === '_' || item[0] === '$') {
return prev;
}
if (typeof nextData[item] === 'function') {
return prev;
}
2024-12-01 11:56:54 +00:00
if (deepEqual(_this.data[item], nextData[item])) {
2024-11-10 07:01:22 +00:00
return prev;
}
// eslint-disable-next-line no-param-reassign
prev[item] = nextData[item];
return prev;
}, {});
if (Object.keys(changedData).length === 0) {
return;
}
this.setData(changedData);
}
2024-12-01 11:56:54 +00:00
export default function () {
var mixin = {
didMount: function () {
computedData.call(this);
},
didUpdate: function () {
computedData.call(this);
},
};
return mixin;
}