**** BEGIN LOGGING AT Tue Nov 18 02:59:59 2014 Nov 18 03:37:38 If a custom Source (such as DB8) knows the results of a query have changed, can it just call sucess agin with the new data? Nov 18 03:38:10 In other words, may the sucess and fail callbacks passed to Source be called more than once? Nov 18 16:32:11 yes, the success/fail callbacks will be called every time you do a fetch/commit. Nov 18 16:32:47 That should be obvious Nov 18 16:32:55 it just uses enyo.Ajax on the backend Nov 18 16:39:57 Actually, I’m asking if Source.fetch() is called *once*, can it call the success callback *multiple times*? Nov 18 16:42:57 DougReeder: why do you need it to? Nov 18 16:43:26 With a DB8 Source, you can set a watch. Nov 18 16:44:19 Once might call fetch to get a list of contact, and then, an hour later, DB8 might be synced with a remote database, and have new info. Nov 18 16:45:03 Are Stores, Collections and Models prepared to accept such unexpected info? Nov 18 16:45:48 DougReeder: I don't think Javascript is prepared to accept such info Nov 18 16:46:55 unless you are suggesting that Source will poll the DB for changes Nov 18 16:47:08 It’s not polling Nov 18 16:47:11 Which I've never heard of enyo.Source doing any such thing Nov 18 16:47:37 DougReeder: Once you make a request and get a response, the asynchronous request is done. There is no "second response" Nov 18 16:47:51 that's how XHR works Nov 18 16:48:14 XHR is not used here. Nov 18 16:50:08 ah Nov 18 16:51:03 well, how are you getting a response, then? To check for a change in the DB states? I don't know of any way that you could receive an interrupt for this Nov 18 16:51:11 aside from XHR Nov 18 16:51:25 Which is why I suggested it would have to be polling Nov 18 16:51:44 the javascript could be on a timer that executes a fetch / merge every XX minutes Nov 18 16:52:26 Cage1___: that's called polling Nov 18 16:52:34 yes Nov 18 16:54:21 DougReeder: dont know much about DB8 but is there a flag that indicates new data? and / or, can it send a signal to your enyo code? Nov 18 16:54:32 A different process on the same machine sends a message over the PalmBus. See https://developer.palm.com/content/api/reference/services/db8.html Nov 18 16:55:23 Particularly https://developer.palm.com/content/api/reference/services/db8.html#find with “watch” set to true. Nov 18 16:56:51 do you know how to call the watch function? ie, the enyo/javascript equivalent to this.controller.serviceRequest... Nov 18 16:58:35 btw, is DbService an enyo2 kind (or was it jsut enyo1) Nov 18 16:59:02 Yes. Calling find with watch=true is effectively the same as calling find, followed by calling watch. Nov 18 17:00:38 https://github.com/webOS-ports/webos-lib supplies the glue to make calls on the PalmBus. Nov 18 17:00:40 hmm, then cant you just send a success handler (onSuccess) with your code to update your collection/models? this woul dbe called every time watch changes Nov 18 17:02:05 Unless the webos lib has some polling mechanism, then you would still have to poll for changes Nov 18 17:02:07 That’s the question - if Source.fetch has been called once, and has called the success callback, is it allowed to call the success callback again? Or will the Store, Collection or Model be confused by that. Nov 18 17:02:34 No polling - another process sends data over the PalmBus. Nov 18 17:02:47 it will call it again Nov 18 17:03:12 DougReeder: Without polling, there is no way for the Javascript to know there is something on the bus Nov 18 17:03:16 and, no, it wont be confused. just make sure you dont use a async function in your successhandler Nov 18 17:03:17 unless there is some custom event? Nov 18 17:04:02 You can think of this as a custom event. Nov 18 17:04:04 godginrai, as i understand it, the glue to make calls on the palmbus takes care of that. the issue woul dbe connecting db8 watch to enyo code Nov 18 17:04:29 Cage1___: I'm looking through the glue right now and so far I'm seeing nothing that "takes care of that" Nov 18 17:07:16 morning enyos Nov 18 17:07:19 whoa scroll back Nov 18 17:07:22 morning dmanderson Nov 18 17:07:39 * DougReeder waves good morning. Nov 18 17:09:29 hmm, there's servicerequest in there (per docs). assuming it take supports dbservice, it should...but then again i only looked at the doc at webos-lib, not source code. Nov 18 17:10:00 if dougreeder says it does, then i'll assume it does :) Nov 18 17:10:05 The source code for it is like any async Nov 18 17:10:24 Except it has code for "subscription" and "resubscription" Nov 18 17:11:13 Subscription is a little different from watch, but they both allow multiple responses. Nov 18 17:11:50 Subscription is for something like a position update every second from GPS. Nov 18 17:11:59 dougreeder, with above assumption, you should be able to just send in your own onSuccess function. it will get called each time there's an update on the db8 side. because all of this occurs async, conflicts could occur if your success function takes a long time to process or if it calls additional async functions (i.e., no guarantee of order of execution). Nov 18 17:12:26 That’s certainly a good point. Nov 18 17:13:09 Since JS is single-threaded, “taking a long time” is not a direct problem here. Nov 18 17:14:21 DougReeder: not really. Async responses interrupt the thread. If the second request responds before the first, your execution is now out of order Nov 18 17:14:29 well, what i mean is if db8 updates once and then updates a second time right away, it will execute two separate instances of your success function. these will not be communicating with each other Nov 18 17:15:29 It’s very straightforward for my custom DB8 Source to call the sucess callback multiple times for single call to fetch. The question is whether, Store, Collection and Model get confused (because they assumed the success callback would only be called once). Nov 18 17:16:03 you can safeguard against this by putting in a flag that is checked in your success function to see if it's already running...however, if you are confident that your success function will execute quickly and db8 wont be updating quicker, you'll be okay Nov 18 17:16:19 the answer to that question is no :) Nov 18 17:16:31 That’s good to hear. Nov 18 17:16:54 maybe Nov 18 17:17:23 hmm, can you rephrase the question... Nov 18 17:17:38 because what you said with first sentence worries me... Nov 18 17:17:53 (maybe i have misunderstood it) Nov 18 17:17:53 Which first sentence? :-) Nov 18 17:18:03 "It’s very straightforward for my custom DB8 Source to call the sucess callback multiple times for single call to fetch." Nov 18 17:20:02 specifically, i'm concerned about you saying "my custom DB8 source calls the success callback multipe times for a _SINGLE_ call to fetch" Nov 18 17:20:25 The success callback passed to a Source is just a function. JS puts no restriction on the numver of times it is called. (Unlike an ES6 Promise, which can only be fulfilled once.) Nov 18 17:20:37 correct Nov 18 17:21:14 but shouldn't it just be calling it once for each fetch? is db8 returning multiple records or just one? Nov 18 17:22:03 Our DB8 Source is communicating with the PalmBus, a different source of events (in the general sense) than the keyboard or XHR. Nov 18 17:23:05 It’s not an issue with multiple records. Nov 18 17:23:27 in other words, what exactly is your db8 service returning? Nov 18 17:24:03 You can use enyo.Singleton to ensure that the exact same callback is being called by the Source, as well as anywhere you want to call it. Nov 18 17:24:42 When our DB8 Source talks to DB8 over the PalmBus, it gets back a response within a second or two, and calls the success callback with all of the requested records. Nov 18 17:24:49 interesting. does that queue them up? or interrupt the first task? Nov 18 17:25:18 and your success callback is calling the add/merge method of a collection? Nov 18 17:25:27 DB8 can return up to 500 records in a single request. Nov 18 17:25:44 if so, then each fetch should be calling the success callback only once... Nov 18 17:27:13 … but, if an hour later, the DB8 database changes outside of my app (probably because it was synced to another database by a different process), DB8 can send a message over the PalmBus to our db8Source. Nov 18 17:27:45 correct...then the success handler would run again...with another call to your collection add/merge Nov 18 17:28:10 Our db8Source then “knows” that, if the query was run now, it would return different results. Nov 18 17:29:02 hmm, not the expert here, but you'll prob want to time how long 500 -1000 records take to process. for example, what if it's doing an update due to db8 watch and then the user hits "update now". then you might encounter a race condition... Nov 18 17:30:00 always good to do recursive processing there and pass control back to the user. Nov 18 17:30:11 yup Nov 18 17:30:49 Wish webworkers were everywhere, and a little more reliable Nov 18 17:31:03 And it would be straighforward for our db8Source to call the success callback again (it’s just a function, not an ES6 Promise). Will Store, Collection and Model be confused? Do Store, Collection and Model assume the success callback will only be called once (though JS can’t enforce such a restriction)? Nov 18 17:31:37 no Nov 18 17:32:20 (only 78% sure) Nov 18 17:32:26 :-) Nov 18 17:32:52 hmm, maybe Nov 18 17:32:54 They wont care, but I would make sure it’s a singleton, so you are ensuring a function isn’t being called multiple times concurrently Nov 18 17:33:02 dmanderson , can you be more sure than 78%? :-) Nov 18 17:33:43 i'm more confident that one call to success handler will be fine. i'm worried if two occur near the same time (ie one running and another one starts). for that, agree that do it as singleton Nov 18 17:33:52 https://github.com/enyojs/enyo/blob/master/source/data/sources/xhr.js#L124 Nov 18 17:34:49 Nothing fancy going on :) Nov 18 17:35:18 the master speaks, and all is well again with the world :) :) :) Nov 18 17:35:36 LOL Nov 18 17:36:03 I wish :) still learning about this framework everyday Nov 18 17:37:04 The example for enyo.singleton says it’s for a given kind. Is there an example fo applying enyo.singleton to a function? http://enyojs.com/docs/latest/api.html#enyo.singleton Nov 18 17:38:14 Don’t you need something more like throttleJob? Nov 19 00:01:29 DougReeder: I'm not sure if I completely get what you're trying to do, but, couldn't you have it when the watch handler fires, it just commits the model to trigger the rest of the Enyo flow? **** ENDING LOGGING AT Wed Nov 19 02:59:59 2014