Created
September 13, 2017 12:33
-
-
Save kaueDM/995c5fc0d4296c168c17e0487648a133 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const checkOpenTasks = (uid) => (dispatch) => | |
new Promise((resolve, reject) => { | |
AsyncStorage.getItem(uid).then(item => { | |
if (item) { | |
const moments = Object.keys(JSON.parse(item)); | |
const last = Math.max.apply(null, moments); //Último moment mesclado ao objeto | |
const { action, initial, elapsed } = JSON.parse(item)[last] //Ação realizada pelo último moment mesclado | |
const now = moment.utc().valueOf(); //Moment presente | |
const extra = (now - last) - ((now - last) % 1000); //Arredondamento - detalhes no README.md | |
resolve({ action, initial, elapsed, extra }) | |
} else { | |
reject(new Error('Nenhuma atividade em aberto')) | |
} | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.