commonjs and API calls with ACS

You must Login before you can answer or comment on any questions.

I am just getting started on converting some apps to the commonjs method, as well as writing a new one, and am starting to get the hang of it. However, my newest app will make use of ACS and I have a concern about API calls, as they are limited and I don't want to be wasteful.

On an old app of mine, I created a tableView window in one of my tabs as soon as the app loaded. I grabbed the rows from my server, and appended them to the tableview. Viola! it was done. I would not make another request to the server again UNLESS data was being changed (add/delete/update). Otherwise, the tableView would just stay how it was.

With commonJS, it seems that the window is being created every time it is viewed. So say I do a: var tvWindow = new tableViewWindow();

and inside tableViewWindow.js, I create a tableview and get data for it from ACS...

That means EVERY time the user goes to this window, a tier 1 API call is used. Having never used ACS, I can't quite grasp how quickly those will be used up, but it seems like there would be a more efficient way.

Is there?

2 Answers

'That means EVERY time the user goes to this window, a tier 1 API call is used.'

Can you confirm that this is ACTUALLY the case? That there are multiple API calls being made?

With a new instantiation, this might be occurring as you are are creating a new object.

var tvWindow = tableViewWindow();

is not the same as

var tvWindow = new tableViewWindow();

— answered 11 months ago by Stephen Feather
answer permalink
1 Comment
  • No I can not confirm that, like I said I am both new to commonJS and to ACS, so I am guessing a bit on the matter. Furthermore, it does not appear that my cloud usage will update when in development, so I can not personally check the amount of calls made. If I am not looking in the right place, I would appreciate a point in the right direction.

    Also, regarding the difference you are pointing out. I have been using a new instantiation every time I navigate window to window within a given tab, which I see may not be the best option. I have been basing my app at a basic level on the todo.sample that floats around here as a starting point to commonJS. The only way it shows to open a window is using new listWindow();

    How would I go about opening a window as a new object the first time, but not for all remaining times(as I assume it won't be and shouldn't be globally available), and if an update were made to the data, is it a better practice to update the tableview directly AFTER a successful API call, or would it be better to create a new window, so that the tableview is rebuilt from the new data?

    — commented 11 months ago by Andrew Woods

Your tableView window can always be architected in a way such that it only retrieves data from the server when you want it to. There is nothing preventing you from caching the data that is a result of the API call

— answered 10 months ago by Aaron Saunders
answer permalink
2 Comments
  • By caching, do you mean saving the data to a sqlite db? I am just trying to get an idea in my head how all of this will work.

    1)API CALL-get tableview data (row 1, row 2, row 3, row 4)

    2)save data to sqlite db

    3)create tableview from sqlite db each time window is viewed

    ---User deletes row 4---

    4)API CALL-delete row 4

    if successful...

    5)remove row 4 from sqlite db

    6)refresh tableivew(how?)

    if failed...

    5)alert and error or 'sorry cant save your data' message

    Is this a sensical way? I know it would result in less API calls, but it sets up a far more complicated architecture where both a local db and a remote(ACS) need to be maintained.

    Is there an easier way to cache this data, or is it typical to just use an API call each time the page is constructed?

    Also, what are your thoughts on Stephen Feather's response above, somehow using var tvWindow = new tableViewWindow(); the first time and just var tvWindow = new tableViewWindow(); after that? Is this bad practice? Should a window always be newly constructed before viewing? Prior to commonJS, my tableView window would have been global, available at any time and already constructed when the app started.

    Thanks for any direction you can provide

    — commented 10 months ago by Andrew Woods

  • Your can save the JSON from the request into a file on the file system, into the database, or into a property (depending on the size of the dataset)

    — commented 10 months ago by Stephen Feather

Your Answer

Think you can help? Login to answer this question!