chore: remove all mixin

This commit is contained in:
chenjiahan 2020-09-25 16:06:16 +08:00
parent 3142266768
commit c2f4165d0f
3 changed files with 0 additions and 129 deletions

View File

@ -1,33 +0,0 @@
/**
* Bind event when mounted or activated
*/
import { on, off } from '../utils/dom/event';
type BindEventMixinThis = {
binded: boolean;
};
type BindEventHandler = (bind: typeof on | typeof off, isBind: boolean) => void;
export function BindEventMixin(handler: BindEventHandler) {
function bind(this: BindEventMixinThis) {
if (!this.binded) {
handler.call(this, on, true);
this.binded = true;
}
}
function unbind(this: BindEventMixinThis) {
if (this.binded) {
handler.call(this, off, false);
this.binded = false;
}
}
return {
mounted: bind,
activated: bind,
deactivated: unbind,
beforeUnmount: unbind,
};
}

View File

@ -1,29 +0,0 @@
import { FIELD_KEY } from '../field';
export const FieldMixin = {
inject: {
vanField: {
from: FIELD_KEY,
default: null,
},
},
watch: {
modelValue() {
const field = this.vanField;
if (field) {
field.resetValidation();
field.validateWithTrigger('onChange');
}
},
},
created() {
const field = this.vanField;
if (field && !field.childFieldValue.value) {
field.childFieldValue.value = () => this.modelValue;
}
},
};

View File

@ -1,67 +0,0 @@
export function ChildrenMixin(parent, options = {}) {
const indexKey = options.indexKey || 'index';
return {
inject: {
// TODO: disableBindRelation
parent: {
from: parent,
default: null,
},
},
computed: {
[indexKey]() {
this.bindRelation();
if (this.parent) {
return this.parent.children.indexOf(this);
}
return null;
},
},
mounted() {
this.bindRelation();
},
beforeUnmount() {
if (this.parent) {
this.parent.children = this.parent.children.filter(
(item) => item !== this
);
}
},
methods: {
bindRelation() {
if (!this.parent || this.parent.children.indexOf(this) !== -1) {
return;
}
const children = [...this.parent.children, this];
// TODO sortChildren
this.parent.children = children;
},
},
};
}
export function ParentMixin(parent) {
return {
provide() {
return {
[parent]: this,
};
},
data() {
return {
children: [],
};
},
};
}