src/apply.js
function apply_patch(context, patch, tracker) {
	const path = patch[0];
	if (path.length == 0) return; //ignore replace root node
	const value = patch[1];
	const len = path.length - 1;
	const prop = path[len];

	if (!Array.isArray(value)) {
		const node = create_node_by_path(context, path, len, tracker);
		commit_node_prop(context, node, prop, value, tracker);
		return;
	} else {
		const patchType = value[0];

		if (patchType == PatchTypes.DEL) {
			return apply_delete_patch(context, path, tracker);
		}
		const node = create_node_by_path(context, path, len, tracker);
		if (patchType == PatchTypes.REFERENCE) {
			const refNode = create_node_by_path(
				context,
				value[1],
				value[1].length,
				tracker
			);
			commit_node_prop(context, node, prop, refNode, tracker);
			return;
		}

		if (patchType == PatchTypes.NODE) {
			if (
				value[1] == undefined &&
				node_type(node[prop]) == NodeTypes.NODE
				//&& node[prop]._.length == undefined
			) {
				return;
			}

			const childNode = create_node(value[1]);
			commit_node_prop(context, node, prop, childNode, tracker);
			return;
		}
	}
}
function apply_patch(context, patch, tracker) {
	const path = patch[0];
	if (path.length == 0) return; //ignore replace root node
	const value = patch[1];
	const len = path.length - 1;
	const prop = path[len];

	if (!Array.isArray(value)) {
		const node = create_node_by_path(context, path, len, tracker);
		commit_node_prop(context, node, prop, value, tracker);
		return;
	} else {
		const patchType = value[0];

		if (patchType == PatchTypes.DEL) {
			return apply_delete_patch(context, path, tracker);
		}
		const node = create_node_by_path(context, path, len, tracker);
		if (patchType == PatchTypes.REFERENCE) {
			const refNode = create_node_by_path(
				context,
				value[1],
				value[1].length,
				tracker
			);
			commit_node_prop(context, node, prop, refNode, tracker);
			return;
		}

		if (patchType == PatchTypes.NODE) {
			if (
				value[1] == undefined &&
				node_type(node[prop]) == NodeTypes.NODE
				//&& node[prop]._.length == undefined
			) {
				return;
			}

			const childNode = create_node(value[1]);
			commit_node_prop(context, node, prop, childNode, tracker);
			return;
		}
	}
}
function apply_patch ( context , patch , tracker ) { const path = patch [ 0 ] ; if ( path . length == 0 ) return ; //ignore replace root node const value = patch [ 1 ] ; const len = path . length - 1 ; const prop = path [ len ] ; if ( ! Array . isArray ( value ) ) { const node = create_node_by_path ( context , path , len , tracker ) ; commit_node_prop ( context , node , prop , value , tracker ) ; return ; } else { const patchType = value [ 0 ] ; if ( patchType == PatchTypes . DEL ) { return apply_delete_patch ( context , path , tracker ) ; } const node = create_node_by_path ( context , path , len , tracker ) ; if ( patchType == PatchTypes . REFERENCE ) { const refNode = create_node_by_path ( context , value [ 1 ] , value [ 1 ] . length , tracker ) ; commit_node_prop ( context , node , prop , refNode , tracker ) ; return ; } if ( patchType == PatchTypes . NODE ) { if ( value [ 1 ] == undefined && node_type ( node [ prop ] ) == NodeTypes . NODE //&& node[prop]._.length == undefined ) { return ; } const childNode = create_node ( value [ 1 ] ) ; commit_node_prop ( context , node , prop , childNode , tracker ) ; return ; } } }
Apply single patch
@param {*} context
@param {*} patch
@param {*} [tracker]
Apply single patch