 
     set: (target, key, value, receiver) ->
 
+      if base.isArray
+        currentLength = target.length
+
       target[key] = value
 
-      if receiver.__prefix__
-        key = "#{receiver.__prefix__}.#{key}"
+      if base.isArray
+        lengthChanged = target.length isnt currentLength
+        return true  if key is 'length' and not lengthChanged
 
-      unless /^__|__$/.test key
-        base.emit 'update', [ key ]
+      if root = receiver[KDData.NAME]
+        key = "#{root}.#{key}"
+      else
+        root = ''
 
+      return true  if /^__|__$/.test key
+
+      if lengthChanged
+        prefix = if key.indexOf('.') >= 0 then "#{root}." else ''
+        base.emit 'update', [ "#{prefix}length" ]
+
+      base.emit 'update', [ key ]
       return true
 
 
-  constructor: (data = {}) ->
+    getPrototypeOf: (target) ->
 
-    super {}
-
-    this.__data__  = data
-    this.__proxy__ = new Proxy data, proxyHandler this
-    this.__proxy__.__proxy__ = {}
-
-    for key, val of this when key not in ['constructor', '__data__']
-      this.__proxy__.__proxy__[key] = val
-
-    return this.__proxy__
+      return KDData.prototype

KDEventEmitter = require './eventemitter'

module.exports = class KDData extends KDEventEmitter

  proxyHandler = (base) ->


      value = target[key]
      return value  if typeof key isnt 'string' or key[0..1] is '__'

      key = getFullPath target, key

      if value and dataValue = KD.utils.JsPath.getAt base.__data__, key
        if dataValue instanceof Object and value not instanceof Date
          proxy = new Proxy value, proxyHandler base
          Object.defineProperty proxy, KDData.NAME, {
            value: key, configurable: yes
          }
          return proxy

      return value
