This is an automated email from the ASF dual-hosted git repository.
carlosrovira pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/royale-docs.git
The following commit(s) were added to refs/heads/master by this push:
new 60c0638 crux: added crux Service Layer page
60c0638 is described below
commit 60c063895ae667fb49820c8d8c7587b1cc185090
Author: Carlos Rovira <[email protected]>
AuthorDate: Tue Feb 18 20:56:10 2020 +0100
crux: added crux Service Layer page
---
libraries/crux/event-handling.md | 16 +++----
libraries/crux/service-layer.md | 91 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 99 insertions(+), 8 deletions(-)
diff --git a/libraries/crux/event-handling.md b/libraries/crux/event-handling.md
index f1edf94..9e4a410 100644
--- a/libraries/crux/event-handling.md
+++ b/libraries/crux/event-handling.md
@@ -30,10 +30,10 @@ Page Contents:
- [Handling Events with
[EventHandler]](libraries/crux/event-handling.html#eventhandler)
- [Event Handling Using Class and Constant
Names](libraries/crux/event-handling.html#eventhandler-class-const-names)
- [Event Handling Using Event Type
Value](libraries/crux/event-handling.html#eventhandler-event-type-value)
-- [[EventHandler] tag options](libraries/crux/event-handling.html#tag-options)
- - [properties
attribute](libraries/crux/event-handling.html#properties-attribute)
- - [Other attributes](libraries/crux/event-handling.html#other-attributes)
-- [Handling Multiple Events from a Single
Method](libraries/crux/event-handling.html#multiple-events-single-method)
+ - [[EventHandler] tag
options](libraries/crux/event-handling.html#tag-options)
+ - [properties
attribute](libraries/crux/event-handling.html#properties-attribute)
+ - [Other attributes](libraries/crux/event-handling.html#other-attributes)
+ - [Handling Multiple Events from a Single
Method](libraries/crux/event-handling.html#multiple-events-single-method)
Crux offers features to assist with both the dispatching and handling of
events within an application. The following sections explain these features in
detail.
@@ -103,7 +103,7 @@ public function handleAddUserEvent( event:UserEvent ):void
}
```
-## [EventHandler] tag options {#tag-options}
+### [EventHandler] tag options {#tag-options}
The examples above show methods that take the target event as an argument, but
in some cases you don't need the event passed to your method. Crux will
intelligently examine the signature of your method and call it without
parameters if that is how it's defined.
@@ -115,7 +115,7 @@ public function handleAddUserEvent():void
}
```
-### properties attribute {#properties-attribute}
+#### properties attribute {#properties-attribute}
You can also specify a comma delimited list of property names in the tag to
have the matching properties pulled off of the event and passed into your
method. This can be useful for allowing methods to be defined in a more
semantic manner to mask the fact that they are event listeners.
@@ -129,11 +129,11 @@ public function addUser( user:User ):void
}
```
-### Other attributes {#other-attributes}
+#### Other attributes {#other-attributes}
Since `[EventHandler]` causes Crux to create an event listener behind the
scenes, it also supports some related attributes. `useCapture`,
`stopPropagation` and `stopImmediatePropagation` are all supported, and Crux
will handle their implementation for you. `useCapture` map directly to the
`useCapture` parameter of the resulting listener. Setting `stopPropagation` or
`stopImmediatePropagation` to `true` will cause Crux to automatically call the
corresponding methods on the event after you [...]
-## Handling Multiple Events from a Single Method
{#multiple-events-single-method}
+### Handling Multiple Events from a Single Method
{#multiple-events-single-method}
It is possible to handle multiple events using a single method:
diff --git a/libraries/crux/service-layer.md b/libraries/crux/service-layer.md
new file mode 100644
index 0000000..803de25
--- /dev/null
+++ b/libraries/crux/service-layer.md
@@ -0,0 +1,91 @@
+---
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+layout: docpage
+title: Service Layer
+description: Learn about how to interact with the server when using Crux
+permalink: /libraries/crux/service-layer
+---
+
+# Service Layer
+
+Learn about how to interact with the server when using Crux
+
+Interacting with remote services is a feature found in almost every RIA, SPA
or Web Application created. Because of this, Crux has made it a priority to
streamline and enhance this aspect of development. There are four primary
classes you will interact with in the service layer of your Crux application.
+
+## ServiceHelper
+
+The `ServiceHelper` class is probably the most common class you will use in
the service layer of your Crux application. `ServiceHelper` is a class that
simplifies and improves your interactions with service classes that return an
`AsyncToken`. This includes `RemoteObject`, `HTTPService` and `WebService`.
These services will typically be defined as beans and injected into one of your
own classes. ServiceHelper's `executeServiceCall()` method is a concise way to
call a service, define hand [...]
+
+The following example shows a simple service call as it looks when using
`ServiceHelper`. In this example the `ServiceHelper` has been defined as a bean
and injected, but you can instantiate your own instance if you prefer. Also
notice that you are able to define an array of parameters that will be passed
to the result handler when the service returns. This can be very useful for
maintaining context between calls and simplifying your result handler code. The
first parameter of `executeSe [...]
+
+```as3
+[Inject( "userService" )]
+public var ro:RemoteObject;
+
+[Inject]
+public var sh:ServiceHelper;
+
+public function fetchUserRoles( user:User ):void
+{
+ sh.executeServiceCall( ro.fetchUserRoles( user.id ),
fetchUserRoles_result, fetchUserRoles_fault, [ user ] );
+}
+
+protected function fetchUserRoles_result( data:Object, user:User ):void
+{
+ user.roles = data.result;
+}
+
+protected function fetchUserRoles_fault( info:Object ):void
+{
+ // handle service fault
+}
+```
+
+## URLRequestHelper
+
+Remote calls that do not return an `AsyncToken` are generally implemented
using the `URLRequest` and `URLLoader` classes. Crux therefore provides the
`URLRequestHelper` class, whose `executeURLRequest()` method works much like
`executeServiceCall()`. The slight differences can be seen below, but can be
summed up in that you do not directly create a `URLLoader` instance or call
`load()` because Crux handles those aspects for you, and there are extra
(optional) handlers that can be defined.
+
+```as3
+[Inject]
+public var urh:URLRequestHelper;
+
+public function loadConfig( user:User ):void
+{
+ urh.executeURLRequest( new URLRequest( "config.xml" ), loadConfig_result,
loadConfig_fault,
+
loadConfig_progress, loadConfig_httpStatus, [ user ] );
+}
+
+protected function loadConfig_result( event:Event, user:User ):void
+{
+ user.config = XML( URLLoader( event.target ).data );
+}
+
+protected function loadConfig_fault( event:Event ):void
+{
+ // will be called in response to an IOErrorEvent.IO_ERROR or
SecurityErrorEvent.SECURITY_ERROR
+}
+
+protected function loadConfig_progress( event:Event ):void
+{
+ // will be called in response to ProgressEvent.PROGRESS
+}
+
+protected function loadConfig_httpStatus( event:Event ):void
+{
+ // will be called in response to HTTPStatusEvent.HTTP_STATUS
+}
+```