thewei / react-native-store

A simple database base on react-native AsyncStorage.
https://github.com/thewei/react-native-store
Other
569 stars 74 forks source link

Dynamically pass storenames as values #27

Closed bozzmob closed 8 years ago

bozzmob commented 8 years ago

Hi, I want to keep the example code(with modifications) as a module. So, can I reference that module with parameters to refer to a store?

Giving an example, say RNStoreUtil is the utility module having all the functions defined by react-native-store (init, destroy, filter, etc etc.,) And say I need a User Model, a Data Model & a History Model.

Can the init() function be something like-

async init(modelName, testDataSet) {
        model = await reactNativeStore.model(modelName);
        for(var element in testDataSet) {
            await model.add(testDataSet[element]);
        }
    }

and from my react native module, can I do something like-

await this.init("user",arrayOfObjects1);
.
.
.
await this.init("data",arrayOfObjects2);
.
.

Similarly other functions^ as well..

Can I do something like this? I tried it, but, I am blocked due to some other issue. So, need some thoughts, so that I can at least finish coding while the other issue is being fixed.

bozzmob commented 8 years ago

Was able to do some hack and got the concept of using stores(not updated in the linked project yet).