Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React native exaple for AsyncStorage with create, get, update, remove #14

Closed
alexicum opened this issue Jul 11, 2016 · 4 comments
Closed

React native exaple for AsyncStorage with create, get, update, remove #14

alexicum opened this issue Jul 11, 2016 · 4 comments

Comments

@alexicum
Copy link

@alexicum alexicum commented Jul 11, 2016

Trying to use feathers-localstorage with React Native and AsyncStorage.

Hang on create, get.
Can not find RN example on base service functions: get, update, remove.

Documentation has code for ReactNative with:
import feathers from 'feathers';
But in chat example:
import feathers from 'feathers/client'

@daffl

This comment has been minimized.

Copy link
Member

@daffl daffl commented Jul 11, 2016

How are you using it? Try to add a .catch(error => console.error(error)) to your service calls (e.g. app.service('myservice').then().catch(error => console.error(error))) to see if there is an error.

@alexicum

This comment has been minimized.

Copy link
Author

@alexicum alexicum commented Jul 12, 2016

Thanks! It helps to understand what's going on without examples.

@alexicum

This comment has been minimized.

Copy link
Author

@alexicum alexicum commented Jul 12, 2016

Previously I had successfully remove item without id with command:
Storage.remove(Number.NaN);

Now I have item with "id":null
(don't ask me how :) )
and no ideas about how to remove it.
Receiving:
Error: No record found for id 'null'(…)
with both code:

Storage.remove(null);

Storage.find()
  .then(tokens)
    for(let token of tokens) {
      Storage.remove(token.id)
        .then((removedToken) => {
          if (removedToken)
            console.log('removed: ' + JSON.stringify(removedToken));
        })
        .catch(error => console.error(error));
...

My storage items:

find(). tokens array: [{"id_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6ImEiLCJpZCI6MiwiaWF0IjoxNDY4MzE0Mzk2LCJleHAiOjE0NjgzMzIzOTZ9.Vep46JizCMLc03bL0-SXpxf1MG6LCduzkGGkOlG_BW8","id":1},{"id_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6ImEiLCJpZCI6MiwiaWF0IjoxNDY4MzE0MDk0LCJleHAiOjE0NjgzMzIwOTR9.iL3WrUkjvqAHwusBH6KoQCjigS7TDZAAKLJBSIHjwJw","id":null}]

@daffl

This comment has been minimized.

Copy link
Member

@daffl daffl commented Jul 14, 2016

The id being null shouldn't really be possible but you can probably remove it manually from AsyncStorage with something like

const storageKey = 'feathers';

AsyncStorage.getItem(storageKey).then(JSON.parse)
  .then(data => data.filter(current => current.id !== null)).
  .then(filteredData => AsyncStorage.setItem(storageKey, JSON.stringify(filteredData));
@daffl daffl closed this Jul 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.