Robotlegs Oil vs promise-as3 for a database service

dkarten's Avatar

dkarten

21 May, 2015 03:06 PM

I recently got very comfortable using the A+ promise-as3 implementation to write a promise based asynchronous SQLite database service. Is there any reason to use Oil over this? Are there any downsides to having your services create promises for commands to consume?

  1. Support Staff 1 Posted by Ondina D.F. on 22 May, 2015 11:04 AM

    Ondina D.F.'s Avatar

    I'd say, use the one you are more comfortable with.
    I like the idea of promises very much, but I've never had a chance to use them in my projects.

    Are there any downsides to having your services create promises for commands to consume?

    I don't think there are any downsides to it. Have you tried anything yet?

  2. 2 Posted by dkarten on 26 May, 2015 01:51 PM

    dkarten's Avatar

    I have a functioning service and all seems to be working well. I had read a discussion on the forums about needing a model to handle promises and their resolution, but cannot seem to find it now. Until something stops working, I'm all set!

  3. Support Staff 3 Posted by Ondina D.F. on 27 May, 2015 10:02 AM

    Ondina D.F.'s Avatar

    I had read a discussion on the forums about needing a model to handle promises and their resolution

    If I understand correctly, this would mean that the Model would make the service call? Having this kind of dependency in a Model is a bad idea, in my opinion.

    A Command could do both, handle the promises and pass the result to the model.

    There are many ways of using promises. You can even let Mediators call services and handle promises, as Shaun has explained in a discussion on this forum.
    I guess that you've already searched the forum and read a lot about promises, so I'm sure that you'll choose the approach that best fits your needs.

    In case you haven't seen it already:

    https://gist.github.com/darscan/470851

  4. 4 Posted by dkarten on 27 May, 2015 03:11 PM

    dkarten's Avatar

    Yes, I figured coupling the model to a service was poor MVCS decision. So a big part of the application is displaying data from the database in the view in DataGrids or DataGroups. For now, I load all the data into the model on startup, and am trying very hard to keep updates to the data tracked in both the db and the model. For example, adding a new record would create a promise that is resolved by the database service, and on resolution add that record to the model. I can see this quickly becoming unwieldy though.

    A Command could do both, handle the promises and pass the result to the model.

    Is it acceptable to add a promise resolver to a command? For example

    public ExecutePromiseCommand extends Command {
        [Inject]
        public var service:IDBService;
        [Inject]
        public var model:DataModel;
        override public function execute():void {
            service.loadData().then(updateModel, loadError).done();
        }
        private function updateModel(data:Array):void {
            //promises resolves with data as function argument
            model.data = data;
        }
        private function loadError(reason:Error):void {
            //handle service error here
        }
    

    I can't say I have seen any RL examples with commands like this. One alternative I see is having functions in the model that handle the promise resolution. Another is creating specific services for each type of data access instead of one general db service and containing the entire db promise-resolve-update chain within the service. I would guess these decisions are really personal preference, but until I get a little more comfortable with RL and MVCS architecture, any wisdom is appreciated!

  5. Support Staff 5 Posted by Ondina D.F. on 27 May, 2015 04:42 PM

    Ondina D.F.'s Avatar

    I have only 2 minutes for a quick answer, before going out for dinner:

    Is it acceptable to add a promise resolver to a command? For example

    Yep. Your example looks good. That's how I'd do it too.

    One alternative I see is having functions in the model that handle the promise resolution.

    Do you mean model.doSomething(data); instead of model.data = data; ?
    That would be ok.

    ...we can continue the discussion tomorrow, if you want...

  6. Support Staff 6 Posted by Ondina D.F. on 28 May, 2015 02:27 PM

    Ondina D.F.'s Avatar

    I would guess these decisions are really personal preference, but until I get a little more comfortable with RL and MVCS architecture, any wisdom is appreciated!

    Yes, in the end, it is a matter of personal preference. But, the problem is that there are many possible solutions to choose from, perhaps too many...and on top of that the new MVCS paradigm makes it even harder for you to decide what to use and how, right?

    For me, it is hard to know how much you already know about MVCS. You make the impression that you're not new to design patterns in general, but just to the 'robotlegs way', yes?
    I don't know what exactly needs clarification. Are you unsure about the roles of Models and Services?
    You seemed to be surprised that a command can access a service and a model. Do you need more explanation on this?

    I've selected a few discussions regarding Services usage that might inspire you:

    Shaun - anti corruption layer:

    http://knowledge.robotlegs.org/discussions/robotlegs-2/38-service-w...

    http://knowledge.robotlegs.org/discussions/questions/215-parallel-s...

    Creynders - Service implementing various interfaces:

    http://knowledge.robotlegs.org/discussions/questions/628-use-of-ser...

    Stray:

    https://gist.github.com/Stray/632333

  7. 7 Posted by dkarten on 29 May, 2015 01:49 PM

    dkarten's Avatar

    Ondina,

    Thanks for all this info, it is really helpful. I am relatively new to both MVCS and Robotlegs. I understand the separation of roles but sometimes struggle with the philosophy in deciding where to place pieces of the program. I am refactoring an existing project, so it is not always as easy as it could be. I actually do have a question about Models and Value Objects, which I will ask in another topic. This issue is all cleared up for me.

  8. Support Staff 8 Posted by Ondina D.F. on 29 May, 2015 03:44 PM

    Ondina D.F.'s Avatar

    No problem! Closing.

  9. Ondina D.F. closed this discussion on 29 May, 2015 03:44 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac