Feb 19 2017 03:07 AM
Still trying to learn SPFx...
source:
 Promises are created and (line 101) immediatly resolved.
Feb 19 2017 07:39 AM - edited Feb 19 2017 07:52 AM
Hi Danny,
This data service introduces the logic, flow, which isn't wired with the "real" data.
Data service operates with a locally stored (in the memory) ITodo[] array, without any physical async requests to SharePoint lists, for instance.
Yet, with such implementation, it's possible to change only the DataService by adding async operations and move resolve() into another promise or a callback, with the other part of the application untouched.
So, no matter that in the example, it can be senseless to introduce promises inside sync piece of code due to its unnecessity, as it might have seen from a first glance, it actually introduces an architecture which can be painlessly extended with async communication with a real server.
Sorry if I understood your question wrong and wrote an obvious explanation of the code example.
--
Best regards,
Andrew
Feb 20 2017 12:45 AM
This code does:
1. Create Promise
2. Loop Items
3. resolve a Promise
4. return Promise
even if no "real" data is wired I do not understand this example
A normal Promise should look like
1. Create Promise AND declare function
A. Loop items
B. resolve Promise
2. return Promise
So why is there a Promise in this SPFX example?
The only reason I could think of is that it is not incorrect code, and TypeScript makes it work.