paulirotta / Tantalum

Tantalum Cross Platform Library
12 stars 6 forks source link

Remove JSONModel, return JSONObject from JSONGetter #7

Closed vivainio closed 11 years ago

vivainio commented 11 years ago

JSONGetter should return JSONObject directly. There is no need to protect from multithreaded access since JSON objects coming over the network are typically used in immutable read-only fashion.

paulirotta commented 11 years ago

I agreed. Then when I started to remove the class, I realized we just need to document the purpose in using JSON as an asynchronously-updatable data model better. Update is below.

vivainio commented 11 years ago

Ok, got it! So Task chain():ed after JSONGetter now get JSONObject is input parameter, right?

paulirotta commented 11 years ago

Yes. JSONModel is a parameter, it holds your current version of the JSONObject. This will automatgically be asynchronously be replaced by the JSONGetter. If you want to be "notified" when this happens, chain().

I don't really like static notifier pattern common in Java. Too rigid. In most cases, the code is much cleaner and most logical flow visible on one screen when you provide your own lambda expression each time you initiate an async operation.

vivainio commented 11 years ago

Yep, but if I chain() a Task after JsonGetter, do I get JSONObject that was received as argument to doInBackground()?

You typically need the whole JSONObject, not the intermediate JSONModel.