{"action":"created","issue":{"url":"https://api.github.com/repos/driftyco/ionic-storage/issues/21","repository_url":"https://api.github.com/repos/driftyco/ionic-storage","labels_url":"https://api.github.com/repos/driftyco/ionic-storage/issues/21/labels{/name}","comments_url":"https://api.github.com/repos/driftyco/ionic-storage/issues/21/comments","events_url":"https://api.github.com/repos/driftyco/ionic-storage/issues/21/events","html_url":"https://github.com/driftyco/ionic-storage/pull/21","id":182797278,"number":21,"title":"Ensure the LocalForage instance is properly initialised","user":{"login":"mirkonasato","id":133967,"avatar_url":"https://avatars.githubusercontent.com/u/133967?v=3","gravatar_id":"","url":"https://api.github.com/users/mirkonasato","html_url":"https://github.com/mirkonasato","followers_url":"https://api.github.com/users/mirkonasato/followers","following_url":"https://api.github.com/users/mirkonasato/following{/other_user}","gists_url":"https://api.github.com/users/mirkonasato/gists{/gist_id}","starred_url":"https://api.github.com/users/mirkonasato/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mirkonasato/subscriptions","organizations_url":"https://api.github.com/users/mirkonasato/orgs","repos_url":"https://api.github.com/users/mirkonasato/repos","events_url":"https://api.github.com/users/mirkonasato/events{/privacy}","received_events_url":"https://api.github.com/users/mirkonasato/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-10-13T13:58:28Z","updated_at":"2016-12-14T17:08:44Z","closed_at":"2016-12-14T14:29:59Z","pull_request":{"url":"https://api.github.com/repos/driftyco/ionic-storage/pulls/21","html_url":"https://github.com/driftyco/ionic-storage/pull/21","diff_url":"https://github.com/driftyco/ionic-storage/pull/21.diff","patch_url":"https://github.com/driftyco/ionic-storage/pull/21.patch"},"body":"There's currently a race condition when Storage / LocalForage is initialised.\n\nLocalForage calls [setDriver](https://github.com/localForage/localForage/blob/1.4.3/src/localforage.js#L119) in its constructor, so it will initially configure itself to use one of the built-in drivers before we call `defineDriver(CordovaSQLiteDriver)`. There's no way to register a custom driver beforehand.\n\nAs a result the first call to `storage.get('k')` can return `null` because it's reading from IndexedDB, even though a few milliseconds later it might be reconfigured to use SQLite and the same call will return some results.\n\nLocalForage provides a [ready](https://github.com/localForage/localForage/blob/1.4.3/src/localforage.js#L250) method but again it only ensures that `setDriver` has finished, it doesn't help when using `defineDriver`.\n\nSo this patch keeps a reference to a promise to ensure the LocalForage instance has been fully initialised with CordovaSQLiteDriver, and uses it in all the API methods.\n\nIt also creates a separate LocalForage instance for Ionic Storage, just in case somebody is using the default LocalForage global instance already for something else.\n\nShould fix #19 and #20.\n"},"comment":{"url":"https://api.github.com/repos/driftyco/ionic-storage/issues/comments/267093076","html_url":"https://github.com/driftyco/ionic-storage/pull/21#issuecomment-267093076","issue_url":"https://api.github.com/repos/driftyco/ionic-storage/issues/21","id":267093076,"user":{"login":"FdezRomero","id":1807985,"avatar_url":"https://avatars.githubusercontent.com/u/1807985?v=3","gravatar_id":"","url":"https://api.github.com/users/FdezRomero","html_url":"https://github.com/FdezRomero","followers_url":"https://api.github.com/users/FdezRomero/followers","following_url":"https://api.github.com/users/FdezRomero/following{/other_user}","gists_url":"https://api.github.com/users/FdezRomero/gists{/gist_id}","starred_url":"https://api.github.com/users/FdezRomero/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FdezRomero/subscriptions","organizations_url":"https://api.github.com/users/FdezRomero/orgs","repos_url":"https://api.github.com/users/FdezRomero/repos","events_url":"https://api.github.com/users/FdezRomero/events{/privacy}","received_events_url":"https://api.github.com/users/FdezRomero/received_events","type":"User","site_admin":false},"created_at":"2016-12-14T17:08:44Z","updated_at":"2016-12-14T17:08:44Z","body":"@mirkonasato @mlynch Can you briefly explain how to initialize Storage after this fix? Thanks!"}}
{"actor":{"display_login":"FdezRomero"}}