tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/12928-robotlegs-oil-vs-promise-as3-for-a-database-serviceRobotlegs: Discussion 2015-08-19T21:05:53Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/369009022015-05-21T15:06:02Z2015-08-19T21:05:52ZRobotlegs Oil vs promise-as3 for a database service<div><p>I recently got very comfortable using the <a href="https://github.com/CodeCatalyst/promise-as3">A+ promise-as3</a>
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?</p></div>dkartentag:robotlegs.tenderapp.com,2009-10-18:Comment/369009022015-05-22T11:04:37Z2015-05-22T11:04:37ZRobotlegs Oil vs promise-as3 for a database service<div><p>I'd say, use the one you are more comfortable with.<br>
I like the idea of promises very much, but I've never had a chance
to use them in my projects.</p>
<blockquote>
<p>Are there any downsides to having your services create promises
for commands to consume?</p>
</blockquote>
<p>I don't think there are any downsides to it. Have you tried
anything yet?</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/369009022015-05-26T13:51:02Z2015-08-19T21:05:52ZRobotlegs Oil vs promise-as3 for a database service<div><p>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!</p></div>dkartentag:robotlegs.tenderapp.com,2009-10-18:Comment/369009022015-05-27T10:02:28Z2015-05-27T10:02:28ZRobotlegs Oil vs promise-as3 for a database service<div><blockquote>
<p>I had read a discussion on the forums about needing a model to
handle promises and their resolution</p>
</blockquote>
<p>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.</p>
<p>A Command could do both, handle the promises and pass the result
to the model.</p>
<p>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.<br>
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.</p>
<p>In case you haven't seen it already:</p>
<p><a href="https://gist.github.com/darscan/470851">https://gist.github.com/darscan/470851</a></p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/369009022015-05-27T15:11:53Z2015-08-19T21:05:52ZRobotlegs Oil vs promise-as3 for a database service<div><p>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.</p>
<blockquote>
<p>A Command could do both, handle the promises and pass the result
to the model.</p>
</blockquote>
<p>Is it acceptable to add a promise resolver to a command? For
example<br></p>
<pre>
<code>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
}</code>
</pre>
<p>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!</p></div>dkartentag:robotlegs.tenderapp.com,2009-10-18:Comment/369009022015-05-27T16:42:49Z2015-05-27T16:42:49ZRobotlegs Oil vs promise-as3 for a database service<div><p>I have only 2 minutes for a quick answer, before going out for
dinner:</p>
<blockquote>
<p>Is it acceptable to add a promise resolver to a command? For
example</p>
</blockquote>
<p>Yep. Your example looks good. That's how I'd do it too.</p>
<blockquote>
<p>One alternative I see is having functions in the model that
handle the promise resolution.</p>
</blockquote>
<p>Do you mean model.doSomething(data); instead of model.data =
data; ?<br>
That would be ok.</p>
<p>...we can continue the discussion tomorrow, if you want...</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/369009022015-05-28T14:27:58Z2015-05-28T14:27:58ZRobotlegs Oil vs promise-as3 for a database service<div><blockquote>
<p>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!</p>
</blockquote>
<p>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?</p>
<p>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?<br>
I don't know what exactly needs clarification. Are you unsure about
the roles of Models and Services?<br>
You seemed to be surprised that a command can access a service
<em>and</em> a model. Do you need more explanation on this?</p>
<p>I've selected a few discussions regarding Services usage that
might inspire you:</p>
<p>Shaun - anti corruption layer:</p>
<p><a href="http://knowledge.robotlegs.org/discussions/robotlegs-2/38-service-with-a-large-api#comment_17269563">
http://knowledge.robotlegs.org/discussions/robotlegs-2/38-service-w...</a></p>
<p><a href="http://knowledge.robotlegs.org/discussions/questions/215-parallel-services-async-commands-etc#comment_2221769">
http://knowledge.robotlegs.org/discussions/questions/215-parallel-s...</a></p>
<p>Creynders - Service implementing various interfaces:</p>
<p><a href="http://knowledge.robotlegs.org/discussions/questions/628-use-of-services-in-loading-assets">
http://knowledge.robotlegs.org/discussions/questions/628-use-of-ser...</a></p>
<p>Stray:</p>
<p><a href="https://gist.github.com/Stray/632333">https://gist.github.com/Stray/632333</a></p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/369009022015-05-29T13:49:53Z2015-08-19T21:05:53ZRobotlegs Oil vs promise-as3 for a database service<div><p>Ondina,</p>
<p>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.</p></div>dkartentag:robotlegs.tenderapp.com,2009-10-18:Comment/369009022015-05-29T15:44:29Z2015-05-29T15:44:29ZRobotlegs Oil vs promise-as3 for a database service<div><p>No problem! Closing.</p></div>Ondina D.F.