This is an automated email from the ASF dual-hosted git repository.
carlosrovira pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
The following commit(s) were added to refs/heads/develop by this push:
new 76ea6ca todomvc-crux: use new AMFStorageBean instead of plain
AMFStorage
76ea6ca is described below
commit 76ea6cac4e97c88d90bb5ce6561859a2da57dd1b
Author: Carlos Rovira <[email protected]>
AuthorDate: Mon Feb 17 12:17:49 2020 +0100
todomvc-crux: use new AMFStorageBean instead of plain AMFStorage
---
.../todomvc-jewel-crux/src/main/royale/App.mxml | 18 +-------
.../main/royale/jewel/todomvc/config/Beans.mxml | 6 ++-
.../jewel/todomvc/controllers/TodoController.as | 11 ++++-
.../main/royale/jewel/todomvc/models/TodoModel.as | 26 ------------
.../todomvc/services/ILocalStorageDelegate.as | 36 ++++++++++++++++
.../jewel/todomvc/services/LocalStorageDelegate.as | 48 ++++++++++++++++++++++
6 files changed, 99 insertions(+), 46 deletions(-)
diff --git a/examples/crux/todomvc-jewel-crux/src/main/royale/App.mxml
b/examples/crux/todomvc-jewel-crux/src/main/royale/App.mxml
index 3d5aec4..1b2e4c7 100644
--- a/examples/crux/todomvc-jewel-crux/src/main/royale/App.mxml
+++ b/examples/crux/todomvc-jewel-crux/src/main/royale/App.mxml
@@ -21,8 +21,7 @@
xmlns:js="library://ns.apache.org/royale/basic"
xmlns:crux="library://ns.apache.org/royale/crux"
xmlns:config="jewel.todomvc.config.*"
- xmlns:views="jewel.todomvc.views.*"
- initialize="setUp()">
+ xmlns:views="jewel.todomvc.views.*">
<fx:Style source="../../main/resources/todomvc-styles.css"/>
@@ -30,21 +29,6 @@
<js:SimpleCSSValuesImpl />
</j:valuesImpl>
- <fx:Script>
- <![CDATA[
- import org.apache.royale.collections.ArrayList;
- import org.apache.royale.reflection.registerClassAlias;
-
- /**
- * Register ArrayCollection alias to map to ArrayList
- */
- public function setUp():void
- {
-
registerClassAlias("flex.messaging.io.ArrayCollection", ArrayList);
- }
- ]]>
- </fx:Script>
-
<j:beads>
<js:ClassAliasBead/>
<!-- support for simulated stage events in javascript (needed for Crux
view processing)-->
diff --git
a/examples/crux/todomvc-jewel-crux/src/main/royale/jewel/todomvc/config/Beans.mxml
b/examples/crux/todomvc-jewel-crux/src/main/royale/jewel/todomvc/config/Beans.mxml
index c46fd74..f53f823 100644
---
a/examples/crux/todomvc-jewel-crux/src/main/royale/jewel/todomvc/config/Beans.mxml
+++
b/examples/crux/todomvc-jewel-crux/src/main/royale/jewel/todomvc/config/Beans.mxml
@@ -20,9 +20,13 @@
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:crux="library://ns.apache.org/royale/crux"
xmlns:models="jewel.todomvc.models.*"
- xmlns:controller="jewel.todomvc.controllers.*">
+ xmlns:controller="jewel.todomvc.controllers.*"
+ xmlns:services="jewel.todomvc.services.*">
<models:TodoModel id="todoModel"/>
<controller:TodoController id="todoController"/>
+ <services:LocalStorageDelegate id="localStorageDelegate"/>
+
+ <crux:AMFStorageBean id="amfStorageBean" name="todomvc"
localPath="crux"/>
</crux:BeanProvider>
\ No newline at end of file
diff --git
a/examples/crux/todomvc-jewel-crux/src/main/royale/jewel/todomvc/controllers/TodoController.as
b/examples/crux/todomvc-jewel-crux/src/main/royale/jewel/todomvc/controllers/TodoController.as
index 33efde6..d4c6229 100644
---
a/examples/crux/todomvc-jewel-crux/src/main/royale/jewel/todomvc/controllers/TodoController.as
+++
b/examples/crux/todomvc-jewel-crux/src/main/royale/jewel/todomvc/controllers/TodoController.as
@@ -20,6 +20,7 @@ package jewel.todomvc.controllers
{
import jewel.todomvc.events.TodoEvent;
import jewel.todomvc.models.TodoModel;
+ import jewel.todomvc.services.ILocalStorageDelegate;
import jewel.todomvc.vos.TodoVO;
import org.apache.royale.collections.ArrayList;
@@ -39,13 +40,19 @@ package jewel.todomvc.controllers
public var model:TodoModel;
/**
+ * the service delegate to store data in the browser
+ */
+ [Inject(source = "localStorageDelegate")]
+ public var delegate:ILocalStorageDelegate;
+
+ /**
* [PostConstruct] methods are invoked after all dependencies
are injected.
* In this example, we set up a default user after the bean is
created.
*/
[PostConstruct]
public function setUp():void {
// retrieve local items and use it if exists
- model.allItems = new ArrayList(model.getItemStore());
+ model.allItems = new ArrayList(delegate.getItemStore());
model.setUpFilteredCollections();
model.listItems = model.allItems;
@@ -159,7 +166,7 @@ package jewel.todomvc.controllers
*/
protected function saveDataToLocal():void {
try {
- model.setItemStore(model.allItems.source);
+ delegate.setItemStore(model.allItems.source);
} catch (error:Error) {
trace("You need to be online to store locally");
}
diff --git
a/examples/crux/todomvc-jewel-crux/src/main/royale/jewel/todomvc/models/TodoModel.as
b/examples/crux/todomvc-jewel-crux/src/main/royale/jewel/todomvc/models/TodoModel.as
index 9251d1f..80d8850 100644
---
a/examples/crux/todomvc-jewel-crux/src/main/royale/jewel/todomvc/models/TodoModel.as
+++
b/examples/crux/todomvc-jewel-crux/src/main/royale/jewel/todomvc/models/TodoModel.as
@@ -23,7 +23,6 @@ package jewel.todomvc.models
import org.apache.royale.collections.ArrayList;
import org.apache.royale.collections.ArrayListView;
import org.apache.royale.events.EventDispatcher;
- import org.apache.royale.storage.AMFStorage;
/**
* Todo Model stores global model variables that are updated by controller
@@ -39,31 +38,6 @@ package jewel.todomvc.models
public static const ACTIVE_FILTER:String = "Active";
public static const COMPLETED_FILTER:String = "Completed";
- public static const STORAGE_PATH:String = "crux";
-
- /**
- * Retrieves the array ot items
- */
- public function getItemStore():Array
- {
- var itemArr:Array = storage.data["items"] || [];
- return itemArr;
- }
-
- /**
- * Saves the array ot items
- */
- public function setItemStore(items:Array):void
- {
- storage.data["items"] = items;
- storage.save();
- }
-
- /**
- * Local storage for the todo items
- */
- private var storage:AMFStorage = AMFStorage.getLocal("todomvc",
STORAGE_PATH);
-
/**
* the list of items binded to the todo list component
*/
diff --git
a/examples/crux/todomvc-jewel-crux/src/main/royale/jewel/todomvc/services/ILocalStorageDelegate.as
b/examples/crux/todomvc-jewel-crux/src/main/royale/jewel/todomvc/services/ILocalStorageDelegate.as
new file mode 100644
index 0000000..890fc5b
--- /dev/null
+++
b/examples/crux/todomvc-jewel-crux/src/main/royale/jewel/todomvc/services/ILocalStorageDelegate.as
@@ -0,0 +1,36 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.
+//
+////////////////////////////////////////////////////////////////////////////////
+package jewel.todomvc.services
+{
+ /**
+ * ILocalStorageDelegate interface is the interface for delgates that
+ * stores data in local browser storage
+ */
+ public interface ILocalStorageDelegate
+ {
+ /**
+ * Retrieves the array ot items
+ */
+ function getItemStore():Array;
+ /**
+ * Saves the array ot items
+ */
+ function setItemStore(items:Array):void;
+ }
+}
\ No newline at end of file
diff --git
a/examples/crux/todomvc-jewel-crux/src/main/royale/jewel/todomvc/services/LocalStorageDelegate.as
b/examples/crux/todomvc-jewel-crux/src/main/royale/jewel/todomvc/services/LocalStorageDelegate.as
new file mode 100644
index 0000000..30b25e4
--- /dev/null
+++
b/examples/crux/todomvc-jewel-crux/src/main/royale/jewel/todomvc/services/LocalStorageDelegate.as
@@ -0,0 +1,48 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.
+//
+////////////////////////////////////////////////////////////////////////////////
+package jewel.todomvc.services
+{
+ import org.apache.royale.crux.storage.AMFStorageBean;
+
+ /**
+ * ILocalStorageDelegate interface is the interface for delgates that
+ * stores data in local browser storage
+ */
+ public class LocalStorageDelegate implements ILocalStorageDelegate
+ {
+ [Inject(source="amfStorageBean", required="true")]
+ public var storage:AMFStorageBean = null;
+
+ /**
+ * Retrieves the array ot items
+ */
+ public function getItemStore():Array
+ {
+ return storage.getValue("items", []) as Array;
+ }
+
+ /**
+ * Saves the array ot items
+ */
+ public function setItemStore(items:Array):void
+ {
+ storage.setValue("items", items);
+ }
+ }
+}
\ No newline at end of file