module.exports = {
	"Text": PropertyModel,
	"Number": PropertyModel,
	"List": PropertyModel
}

var fin = require('../client') 

/* Property model types (Text/Number, List/Set)
 **********************************************/
function PropertyModel(value) { this._value = value }
PropertyModel.prototype = {
	observe: _modelObserve,
	on: _modelOn
}

function _modelObserve(callback) {
	_observe(this, function(mutation) {
		callback(mutation.args, mutation.op)
	})
}

function _modelOn(mutationType, callback) {
	_observe(this, function(mutation) {
		if (mutation.op != mutationType) { return }
		// TODO if this is a List/Set model, and the type "of" is a CustomModel,
		// then instantiate that model and pass it as the argument to callback
		callback(mutation.args)
	})
}

/* Util function. All callbacks get called
 * in the context of the model passed in
 *****************************************/
var _observe = function(propertyModel, callback) {
	var info = _getObservationInfo(propertyModel)
	fin.observe(info.id, info.chain, function(mutation) {
		callback.call(propertyModel, mutation)
	})
}

var _getObservationInfo = function(propertyModel) {
	var propertyNameChain = []
	while(propertyModel._parent) {
		propertyNameChain.push(propertyModel._propertyID)
		propertyModel = propertyModel._parent
	}
	return { id:propertyModel._id, chain:propertyNameChain }
}

@@ -118,17 +118,48 @@
 client')
- 
+,%0A%09util = require('../fin/util')
 %0A%0A/* Pro
@@ -277,20 +277,42 @@
 el(value
+, propertyDescription
 ) %7B
- 
+%0A%09
 this._va
@@ -322,17 +322,108 @@
  = value
- 
+%0A%09if (!propertyDescription) %7B propertyDescription = %7B%7D %7D%0A%09this._of = propertyDescription.of%0A
 %7D%0AProper
@@ -542,32 +542,33 @@
 s, function(
-mutation
+value, op
 ) %7B%0A%09%09callba
@@ -574,32 +574,15 @@
 ack(
-mutation.args, mutation.
+value, 
 op)%0A
@@ -653,32 +653,33 @@
 s, function(
-mutation
+value, op
 ) %7B%0A%09%09if (mu
@@ -676,25 +676,16 @@
 %7B%0A%09%09if (
-mutation.
 op != mu
@@ -713,178 +713,26 @@
 %7D%0A%09%09
-// TODO if this is a List/Set model, and the type %22of%22 is a CustomModel,%0A%09%09// then instantiate that model and pass it as the argument to callback%0A%09%09callback(mutation.args
+callback(value, op
 )%0A%09%7D
@@ -961,17 +961,55 @@
 tyModel)
+,
 %0A
+%09%09of = propertyModel._of%0A%09if (of) %7B%0A%09
 %09fin.obs
@@ -1012,16 +1012,20 @@
 .observe
+List
 (info.id
@@ -1065,50 +1065,357 @@
 %7B%0A%09%09
-callback.call(propertyModel, mutation)%0A%09%7D)
+%09var Model = fin._propertyModels%5Bof%5D %7C%7C fin._customModels%5Bof%5D,%0A%09%09%09%09op = mutation.op%0A%09%09%09util.each(mutation.args, function(arg) %7B%0A%09%09%09%09callback.call(propertyModel, new Model(arg), op)%0A%09%09%09%7D)%0A%09%09%7D)%0A%09%7D else %7B%0A%09%09fin.observe(info.id, info.chain, function(mutation) %7B%0A%09%09%09var value = mutation.args%5B0%5D%0A%09%09%09callback.call(propertyModel, value, mutation.op)%0A%09%09%7D)%0A%09%7D
 %0A%7D%0A%0A

Support observation of lists