Process.js 795 Bytes
Newer Older
rockyl's avatar
rockyl committed
1 2 3 4 5
/**
 * Created by rockyl on 2019-09-29.
 */

export default class Process {
rockyl's avatar
rockyl committed
6 7
	constructor(parent, data, resolveProcess) {
		this._resolveProcess = resolveProcess;
rockyl's avatar
rockyl committed
8 9
		this._parent = parent;
		this._data = data;
rockyl's avatar
rockyl committed
10 11 12 13 14
		if (typeof data.meta === 'string') {
			this.metaID = data.meta;
		} else {
			this.meta = data.meta;
		}
rockyl's avatar
rockyl committed
15 16
	}

rockyl's avatar
rockyl committed
17
	get data() {
rockyl's avatar
rockyl committed
18 19 20
		return this._data;
	}

rockyl's avatar
rockyl committed
21 22 23 24 25 26 27 28
	get parent() {
		return this._parent;
	}

	get uuid() {
		return this._data.uuid;
	}

rockyl's avatar
rockyl committed
29 30 31 32 33
	set metaID(id) {
		this._data.meta = id;
		this.meta = this.resolveMeta(id);
	}

rockyl's avatar
rockyl committed
34
	resolveMeta(id) {
rockyl's avatar
rockyl committed
35
		let meta = this.meta && this.meta.metas ? this.meta.metas.find(meta => meta.id === id) : null;
rockyl's avatar
rockyl committed
36
		if (!meta && this._parent) {
rockyl's avatar
rockyl committed
37
			meta = this._parent.resolveMeta(id);
rockyl's avatar
rockyl committed
38
		}
rockyl's avatar
rockyl committed
39
		if (!meta) {
rockyl's avatar
rockyl committed
40
			meta = this._resolveProcess(id);
rockyl's avatar
rockyl committed
41 42 43 44 45
		}

		return meta;
	}
}