This commit is contained in:
Ling53666
2025-08-18 09:11:51 +08:00
commit 02554225da
2516 changed files with 133155 additions and 0 deletions

View File

@ -0,0 +1,4 @@
export default function (): {
didMount(): void;
didUpdate(): void;
};

View File

@ -0,0 +1,38 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import deepEqual from 'fast-deep-equal';
import { getValueFromProps } from '../_util/simply';
function computedData() {
var _this = this;
var nextData = this.computed(getValueFromProps(this));
// 浅比较就行了
var changedData = Object.keys(nextData).reduce(function (prev, item) {
// 移除 _ $ 开头的保留 props
if (item[0] === '_' || item[0] === '$') {
return prev;
}
if (typeof nextData[item] === 'function') {
return prev;
}
if (deepEqual(_this.data[item], nextData[item])) {
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);
}
export default function () {
var mixin = {
didMount: function () {
computedData.call(this);
},
didUpdate: function () {
computedData.call(this);
},
};
return mixin;
}

View File

@ -0,0 +1,22 @@
import { IMixin4Legacy } from '@mini-types/alipay';
declare const _default: ({ valueKey, defaultValueKey, scopeKey, transformValue, }?: {
valueKey?: string;
defaultValueKey?: string;
scopeKey?: string;
transformValue?: (this: any, value: any, extra: {
nextProps: Record<string, any>;
}, ...args: any) => {
needUpdate: boolean;
value?: any;
};
}) => IMixin4Legacy<Record<string, any>, Record<string, any>, {
getValue(prevData?: any): any;
isControlled(): boolean;
updateControlled(): void;
update(val: any, extra?: any, ...args: any): {
needUpdate: boolean;
value: any;
};
isEqualValue(prevData: any): boolean;
}, MiniProgram.UnknownRecord, MiniProgram.UnknownRecord>;
export default _default;

View File

@ -0,0 +1,114 @@
import { __spreadArray } from "tslib";
import { getValueFromProps } from '../_util/simply';
function equal(a, b) {
if (a === b) {
return true;
}
if (a !== a && b !== b) {
return true;
}
return false;
}
var component2 = my.canIUse('component2');
export default (function (_a) {
var _b;
var _c = _a === void 0 ? {} : _a, _d = _c.valueKey, valueKey = _d === void 0 ? 'value' : _d, _e = _c.defaultValueKey, defaultValueKey = _e === void 0 ? 'defaultValue' : _e, _f = _c.scopeKey, scopeKey = _f === void 0 ? 'mixin' : _f, _g = _c.transformValue, transformValue = _g === void 0 ? function (value) { return ({
needUpdate: true,
value: value,
}); } : _g;
var mixin = {
data: (_b = {},
_b[scopeKey] = {
value: undefined,
updated: false,
controlled: false,
},
_b),
onInit: function () {
this.init();
},
deriveDataFromProps: function (nextProps) {
if (!equal(nextProps[valueKey], getValueFromProps(this, valueKey))) {
this.update(nextProps[valueKey], {
nextProps: nextProps,
});
}
},
didUpdate: function (prevProps) {
if (component2) {
return;
}
if (!equal(prevProps[valueKey], getValueFromProps(this, valueKey))) {
this.update(getValueFromProps(this, valueKey), {
nextProps: getValueFromProps(this),
});
}
},
didMount: function () {
if (component2) {
return;
}
this.init();
},
methods: {
init: function () {
var value;
value =
getValueFromProps(this, valueKey) !== undefined
? getValueFromProps(this, valueKey)
: getValueFromProps(this, defaultValueKey);
var needUpdate = this.update(value, {
nextProps: getValueFromProps(this),
}).needUpdate;
if (!needUpdate) {
this.updateControlled();
}
},
getValue: function (prevData) {
return (prevData || this.data)[scopeKey].value;
},
isEqualValue: function (prevData) {
if (!prevData[scopeKey].updated) {
return true;
}
return equal(this.getValue(prevData), this.getValue());
},
isControlled: function () {
if ('controlled' in getValueFromProps(this)) {
return getValueFromProps(this, 'controlled');
}
return valueKey in getValueFromProps(this);
},
updateControlled: function () {
var _a;
this.setData((_a = {},
_a[scopeKey] = {
controlled: this.isControlled(),
},
_a));
},
update: function (val, extra) {
var _a;
var args = [];
for (var _i = 2; _i < arguments.length; _i++) {
args[_i - 2] = arguments[_i];
}
var _b = transformValue.call.apply(transformValue, __spreadArray([this, val, extra], args, false)) || {}, needUpdate = _b.needUpdate, value = _b.value;
if (needUpdate) {
this.setData((_a = {},
_a[scopeKey] = {
value: value,
updated: true,
controlled: this.isControlled(),
},
_a));
}
return {
needUpdate: needUpdate,
value: value,
};
},
},
};
return mixin;
});