Sunday, May 24, 2009

my gsoc2009 @ May 24

This week, I finished abstracting the Ext.ajax.request() and reflect corresponding changes in phps.

The major reason for abstracting the pretty good Ext.ajax.request() is that ... we may save some lines for those repeating things like the url of the web service... And another reason is that I know how doc-editor works throughout all request-and-response.

To have a brief review on main.js ... it's a one-big-ui-class with many methods ... those ui-components can be classified by their nature of task ... The following code block can explain the situation...


class something_like_the_main {
task1 : function() {
define_ui_of_task1();
fire_any_XHR_to_construct_the_ui();
show_the_ui_for_task1();
},
task2 : function() {
define_ui_of_task2();
fire_any_XHR_to_construct_the_ui();
show_the_ui_for_task2();
}
...
...
taskN : function() {
// feels like copy & paste from above tasks...................
}
}


As you can see, this make my life easier to break them into different large piece ui components. But.. probably these large piece ui-components are not reusable for other task ... Anyway... i'm not making an ui library so that's not a problem =]

Let's get back to the XHR abstraction. From extjs implementation of ext.ajax.request() method ...
- success callback will be invoked if (httpStatus >= 200 && httpStatus < 300) || (httpStatus == 1223 for IE)
- failure callback will be invoked else
- request callback will be invoked right after calling success/failure callback

And, most (but not every) XHRs in doc-editor depend on the "success" attribute in the response json string to make decision. So, why not slightly improve the readability by re-directing those response with "success: false" to the failure callback and free the success callback by a single if-else branching ??

As a result ... the abstraction is made as follow.



Followed by this decision, I need to reflect the changes in phps. In php... there are 3 routines something like ...

1) getResponse( $mixed ) {return json_encode($mixed); }
2) getSuccess() { return getResponse( array( 'success' => true ) ); }
3) getFailure( $message ) { return getResponse( array( 'success' => false, 'msg' => $message ) ); }

XHR request handlers depend on this 3 functions ... sometimes getFailure-getResponse pair while sometimes getFailure-getSuccess pair. So, I decide to unite them.

It's pretty simple ... change all handlers into getFailure-getSuccess pair and then the XHR abstraction should work. Hence, following codes resulted.





However, when i try to test out the changes ... Something failed... The repository tree failed to load and not files can be retrieved... So, i go back to main.js and see what's matter. It's tricky... the tree nodes are loaded by ext.tree.TreeLoader in which this loader can only accepts json with ext-tree-node config ... While ... the php is returning something like ... { success : true, 1 : tree_node_config1, 2 : tree_node_config2, ... }. A solution is to rollback the change on the repository request handler and allows it to use getResponse instead of getSuccess.

No response to “my gsoc2009 @ May 24”

 
© 2009 Emptiness Blogging. All Rights Reserved | Powered by Blogger
Design by psdvibe | Bloggerized By LawnyDesignz