import Model from './Model';
import { handleChange } from '../shared/methodCallers';

export default class ComputationChild extends Model {
	get () {
		const parentValue = this.parent.get();
		return parentValue ? parentValue[ this.key ] : undefined;
	}

	handleChange () {
		this.dirty = true;

		this.deps.forEach( handleChange );
		this.children.forEach( handleChange );
		this.clearUnresolveds(); // TODO is this necessary?
	}

	joinKey ( key ) {
		if ( key === undefined || key === '' ) return this;

		if ( !this.childByKey.hasOwnProperty( key ) ) {
			const child = new ComputationChild( this, key );
			this.children.push( child );
			this.childByKey[ key ] = child;
		}

		return this.childByKey[ key ];
	}

	set () {
		throw new Error( `Cannot set read-only property of computed value (${this.getKeypath()})` );
	}
}

@@ -711,16 +711,79 @@
 %5D;%0A%09%7D%0A%0A%09
+// TODO this causes problems with inter-component mappings%0A%09// 
 set () %7B
@@ -784,16 +784,19 @@
 t () %7B%0A%09
+// 
 %09throw n
@@ -882,12 +882,15 @@
 %7D)%60 );%0A%09
+// 
 %7D%0A%7D%0A

disable #2123 fix