hiposfer / hive

Your go-to routing app for public transport
GNU Lesser General Public License v3.0
10 stars 0 forks source link

Transact - refactored #128

Closed carocad closed 6 years ago

carocad commented 6 years ago

Previously we had to do (run! transact! (my-custom-transaction)) to execute a series of transactions together with side-effects.

This worked well for some cases, however, in the case of asynchronous function the behaviour was not clear. Since the user was the one executing the transaction (when it is available) we were forced to assume that the result of a promise was a single transaction element.

The problem arises when the result of one promise is meant to create more promises together with a transaction. There was just no way to do this before. In particular, the case that I had was that the result from kamal directions/ endpoint returns GTFS entities which I also want to request from kamal (such as trip headsign or route color/type), but there was no way to do this due to the assumption above.

This PR attempts to change that merging together Datascript transactions with effect execution and asynchronous function.

From now on, all effects are executed first and then we update the Datascript db with the transaction.

mehdisadeghi commented 6 years ago

:shipit: This branch has been deployed to: https://expo.io/@carocad/hive?release-channel=transact

Download the Expo app and scan this QR code to get started!

QR Code

mehdisadeghi commented 6 years ago

So basically this is promise chaining.

carocad commented 6 years ago

So basically this is promise chaining.

partially yes. This is about promises that returns transaction which contain other promises.

Promise-inception if you would prefer 😅

mehdisadeghi commented 6 years ago

:shipit: This branch has been deployed to: https://expo.io/@carocad/hive?release-channel=transact

Download the Expo app and scan this QR code to get started!

QR Code