LocalPersistenceMap

When developing browser based Flex applications, SharedObject provides just about everything one needs to facilitate local persistence of application data. While being somewhat restricted by certain rules governed by the Flash Player Security Model, in general, it provides a rather simple solution for most needs.

The data property of a SharedObject provides read/write access to the underlying data which is persisted to the SharedObject. Personally, I prefer to have a consistent API available when working with dynamic objects, thus I developed the IMap interface.

LocalPersistenceMap provides an IMap implementation into the data property of a SharedObject instance. It allows clients to work with the underlying data of a SharedObject just as one would with a HashMap, ResourceMap, etc.

Below is a basic example which demonstrates how LocalPersistenceMap can be utilized to provide an IMap implementation into a SharedObject:

The LocalPersistenceMap constructor creates a reference to a local SharedObject based on the specified identifier and optional local path. A reference to the underlying SharedObject can also be retrieved via the sharedObjectInstance accessor.

In addition to the new LocalPersistenceMap, I have also packaged the Collections API which can be downloaded here. Complete documentation and code examples for the Collections API are also available here.

{ 8 comments to read ... please submit one more! }

  1. Nice library.

    I am wondering if you can store more complex information aswell. It would be nice for example if you would build in a check to see if complex objects have been registered before putting them in, something like this (from the top of my head):

    function put(key:String, object:Object):void
    {
    var ba:ByteArray = new ByteArray();
    ba.writeObject(object);
    ba.position = 0;

    var newObject:Object = ba.readObject();

    if (describeType(object).@name != describeType(newObject).@name)
    {
    throw new Error (“If you save complex objects, make sure you use registerClassAlias to make sure they can be stored”);
    };

    };

    It is just an idea 🙂

    Greetz Erik

  2. Good point, initially I thought of this as well, however I opted not to perform the check as the IMap implementation is only intended to provide an interface into the data. The call to registerClassAlias is assumed by the client implementation as the internal check makes the implementation quite expensive to perform when it is not needed if the object is a value type.

    With that being said I realized some people may want to perform the check internally therefore I did not define the LocalPersistenceMap as final so developers can extend to implement additional functionality such as this as needed.

    Thanks,
    Eric

  3. Hi Eric,
    Thanks for this great API!
    But it seems like Collections.zip archive isn’t available at http://code.ericfeminella.com/downloads/Collections.zip
    Could you please fix or update the link?

  4. Hi Eric,
    this class sound very interesting, could you please fix the download link?

    Cheers,
    Fabien

{ 0 Pingbacks/Trackbacks }