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

Does this lib support redux-persist v5 or v4 only? #2

Open
fungilation opened this issue Nov 11, 2017 · 2 comments · May be fixed by #3 or #4
Open

Does this lib support redux-persist v5 or v4 only? #2

fungilation opened this issue Nov 11, 2017 · 2 comments · May be fixed by #3 or #4

Comments

@fungilation
Copy link

https://github.com/rt2zz/redux-persist#v5-breaking-changes

@sytolk
Copy link

sytolk commented Dec 7, 2017

It's work only with v.4 this is error with redux-persist v.5

error      TypeError: callback is not a function
    at RealmPersistInterface.getItem (RealmPersistInterface.js:29)
    at getStoredState (getStoredState.js:16)
    at persistReducer.js:71
    at dispatch (createStore.js:178)
    at redux-logger.js:1
    at Object.dispatch (index.js:14)
    at Object.persistor.persist (persistStore.js:107)
    at persistStore (persistStore.js:110)
    at createReduxStore (store.js:46)
    at main.js:16

@sytolk sytolk linked a pull request Dec 7, 2017 that will close this issue
@albertpb albertpb linked a pull request Jun 3, 2018 that will close this issue
@biboukat
Copy link

biboukat commented Dec 5, 2018

@fungilation

import Realm from 'realm';

class RealmPersistInterface {
constructor() {
this.realm = new Realm({
schema: [
{
name: 'Item',
primaryKey: 'name',
properties: {
name: 'string',
content: 'string',
},
},
],
});
this.items = this.realm.objects('Item');
}

getItem = key => {
console.log('bla key', key);
return new Promise((resolve, reject) => {
const matches = this.items.filtered(name = "${key}");
if (matches.length > 0 && matches[0]) {
resolve(matches[0].content);
} else {
throw new Error(Could not get item with key: '${key}');
}
});
};

setItem = (key, value) => {
return new Promise((resolve, reject) => {
this.realm.write(() => {
this.realm.create(
'Item',
{
name: key,
content: value,
},
true
);
});
});
};

removeItem = (key, callback) => {
return new Promise((resolve, reject) => {
this.realm.write(() => {
const item = this.items.filtered(name = "${key}");
this.realm.delete(item);
});
});
};
}

const singleton = new RealmPersistInterface();

export default singleton;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants