Skip to content

Commit

Permalink
Reworked component watcher a bit, still somewhat flaky, fixed
Browse files Browse the repository at this point in the history
changeresponder to deal with syncing responses from
XMLHTTServiceProvider a bit better.
  • Loading branch information
Dima Berastau committed Feb 10, 2009
1 parent 02070e2 commit e567e40
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
7 changes: 2 additions & 5 deletions framework/src/org/restfulx/components/rx/ComponentWatcher.as
Expand Up @@ -71,7 +71,6 @@ package org.restfulx.components.rx {
*/
public function set model(value:Object):void {
_model = value;
updateBinding();
}

/**
Expand All @@ -88,7 +87,6 @@ package org.restfulx.components.rx {
*/
public function set field(value:String):void {
_field = value;
updateBinding();
}

/**
Expand Down Expand Up @@ -138,8 +136,7 @@ package org.restfulx.components.rx {
private function updateBinding():void {
if (bound) clearBinding();

if (model != null && model.hasOwnProperty(field)
&& target != null && target.hasOwnProperty(property)) {
if (target && target.hasOwnProperty(property)) {
componentWatcher = ChangeWatcher.watch(target, property, onChange, true);
bound = true;
}
Expand All @@ -155,7 +152,7 @@ package org.restfulx.components.rx {
}

private function onChange(event:Event):void {
if (model[field] != event.target[property]) {
if (model && model.hasOwnProperty(field) && model[field] != event.target[property]) {
model[field] = event.target[property];
model["dirty"] = true;
}
Expand Down
2 changes: 1 addition & 1 deletion framework/src/org/restfulx/components/rx/RxAutoComplete.as
Expand Up @@ -273,7 +273,7 @@ package org.restfulx.components.rx {
}

private function onResourceShow(result:Object):void {
//selectedItem = result;
selectedItem = result;
preselectedItem = false;
preselectedObject = null;
if (clearTextAfterFind) clearTypedText();
Expand Down
3 changes: 3 additions & 0 deletions framework/src/org/restfulx/models/RxModel.as
Expand Up @@ -46,6 +46,9 @@ package org.restfulx.models {

/** can be used to see if this model's properties have been changed */
public var dirty:Boolean;

/** indicates if this is a clone */
public var cloned:Boolean;

/** any model can have one attachment, this can be either RxFileRefrence or BinaryAttachment */
public var attachment:Object;
Expand Down
3 changes: 3 additions & 0 deletions framework/src/org/restfulx/services/ChangeResponder.as
Expand Up @@ -74,6 +74,9 @@ package org.restfulx.services {
if (!destination.hasErrors(event.result)) {
controller.count--;
var target:Object = destination.unmarshall(event.result, true);
if (RxUtils.isEmpty(target["rev"])) {
target["rev"] = 0;
}
target["xrev"] = item["rev"];
switch (action) {
case ChangeController.CREATE :
Expand Down
16 changes: 13 additions & 3 deletions framework/src/org/restfulx/utils/RxUtils.as
Expand Up @@ -58,6 +58,7 @@ package org.restfulx.utils {
"xrev",
"sync",
"dirty",
"cloned",
"attachment",
"prototype"
];
Expand Down Expand Up @@ -92,11 +93,15 @@ package org.restfulx.utils {

/**
* If the object cloned is a RxModel do clone based on reflection, else
* default to binary ObjectUtil clone.
* default to binary ObjectUtil clone. Recursive cloning can be very slow
* and should be avoided for large trees.
*
* @param object object to clone
* @param recursive indicates if references RxModels should be cloned too
*
* @return cloned RxModel instance
*/
public static function clone(object:Object):Object {
public static function clone(object:Object, recursive:Boolean = false):Object {
if (object is RxModel) {
var fqn:String = getQualifiedClassName(object);
var clazz:Class = getDefinitionByName(fqn) as Class;
Expand All @@ -105,11 +110,16 @@ package org.restfulx.utils {
cloned["rev"] = object["rev"];
cloned["xrev"] = object["xrev"];
cloned["sync"] = object["sync"];
cloned["cloned"] = true;
for each (var node:XML in describeType(object)..accessor) {
if (!isInvalidPropertyName(node.@name)) {
try {
var name:String = node.@name;
cloned[name] = object[name];
if (recursive && object[name] is RxModel && object[name] != null && !object[name]["cloned"]) {
cloned[name] = clone(object[name]);
} else {
cloned[name] = object[name];
}
} catch (e:Error) {
// we can fail cloning if the property is read-only, etc.
}
Expand Down

0 comments on commit e567e40

Please sign in to comment.