 
 # Construct a thingy.
 #
-# @param [String] typename   Name of thingy type.
-# @param [String] id         ID.
-# @param [Object] attrs      Initial attributes.
-# @param [Object] local_data Local data, if any.
+# @param [String]        typename   Name of thingy type.
+# @param [String]        id         ID.
+# @param [Object]        attrs      Initial attributes.
+# @param [Object]        local_data Local data, if any.
+# @param [Array<String>] subkeys    Which subkeys were received. null
+#   for local creation.
 # @return [thingy] New thingy.
 # @throw [String] If `typename` isn't known.
 # @throw [String] If `id` already exists.
-make_thingy = ( typename, id, attrs, local_data ) ->
+make_thingy = ( typename, id, attrs, local_data, subkeys = null ) ->
   if ! typename?
     @_.on_error( "Missing typename for thingy: #{id}" )
   @_.make_guard = true
   thingy = new Heron.Thingy( this, typename, id, attrs, local_data )
   @_.make_guard = false
+
+  # Subkey reconciliation.  Need to create any subkeys in definition but not
+  # subkeys and remove any in subkeys but not definition.
+  if subkeys?
+    real_subkeys = {}
+    real_subkeys[ subkey ] = true for subkey of @_.per_type[ typename ].subkeys
+    to_delete = []
+    for subkey in subkeys
+      if real_subkeys[ subkey ]
+        delete real_subkeys[ subkey ]
+      else
+        to_delete.push( subkey )
+    to_push = Heron.Util.keys( real_subkeys )
+
+    @_.dictionary.batch( =>
+      for subkey in to_delete
+        @_.dictionary.delete( @domain(), subkey )
+      for subkey in to_push
+        @_.send_create_subkey( thingy, subkey )
+    )
+
   thingy
 
 # Create all partials.


  @_.dictionary.batch =>
    for subkey, attr_keys of type_data.subkeys
      key   = subkey_key( id, subkey )
      value = only_keys( thingy.get( attr_keys... ), attr_keys )
      if subkey == '_'
        value =
          typename: typename
          attrs: value
      @_.dictionary.create( @_.domain, key, value )
    # %create tells others to create the thingy.
    @_.dictionary.create( @_.domain, '%create', id )


        send_update_subkey.call( this, thingy, subkey )
      send_create: ( thingy ) =>
        send_create.call( this, thingy )
      send_create_subkey: ( thingy, subkey ) =>
        send_create_subkey.call( this, thingy, subkey )
      make_thingy: ( typename, id, domain, attrs, local_data, subkeys ) =>
        make_thingy.call( this, typename, id, domain, attrs, local_data, subkeys )
      flush_partials: =>
        flush_partials.call( this )

