maintained data that is held in memory.
When constructed, it has a property called "data" that holds the initial data of the store.
dojo/store/Observable
When one executes a query on a store and that store is an Observable, then a function called
"observe()" may be executed on the returned results. This causes the results to be "monitored"
and if the results would change as if executed again, the function passed by "observe()" is
called. This function is passed three parameters:
• item – The item that changed
• removedFrom – Where the item was removed from
• insertedInto – Where the item was inserted into
The formal syntax of observe() is:
observe(function(item, removedFrom, insertedInto), includeObjectUpdates)
The includeObjectUpdates defines whether or not the changes to the content of the data will
be flagged. The default is false.
Deferred and asynchronous processing – dojo/Deferred
Within Dojo, there are times where we wish some action to be executed and, when completed, to
invoke a callback with the results. This is very common with AJAX programming. Dojo provides
assistance with this function through the "Deferred" capabilities.
Here is a high level skeleton
function myAsync() {
var deferred = new Deferred();
doSomethingInBackground(function(X) {
deferred.resolve(X);
});
return deferred.promise;
}
// caller
myAsync().then(function(Y) {
… process result;
});
The concept is that when something may happen in the background, the provider of that something
returns an instance of a "Deferred". Deferred has a method on it called "then()" which takes
a function as a parameter. When the background thing has completed, the provider of the
background service calls the method called "resolve()" on the Deferred object. This is what
triggers the "then()" function.
If the asynchronous function should fail, it may issue the "reject()" method to indicate that this has
happened.
See also:
• Dojo Programming Reference – Deferred – 1.9
Declare - Defining Dojo Classes
JavaScript can be confusing to folks skilled in other object oriented languages such as Java or C++.
The question asked is "Is JavaScript OO or not?". I don't have enough theoretical knowledge to
Page 201
Kommentare zu diesen Handbüchern