A Vuex plugin that enables you to save the state of your NativeScript app to the SharedPreferences on Android and NSUserDefaults on iOS via the Application Settings module
npm install --save ns-vuex-persist
One of the use cases for this package is to store the user session on native device storage. Import the module from "ns-vuex-persist" and pass an instance of it to vuex as a store plugin. The module takes an optional array param in order to filter the modules that need to be persisted.
import Vue from 'vue'
import Vuex from 'vuex'
import NSVuexPersist from 'ns-vuex-persist'
/** Store modules */
import session from './modules/session/'
import todo from './modules/todo/'
Vue.use(Vuex)
const store = new Vuex.Store({
modules: { session },
plugins: [NSVuexPersist(['session'])]
})
export default store
ns-vuex-persist contains an implentation of the "Storage" interface provided by @championswimmer in vuex-persist . This class is called NativeStorage and wraps the NativeScript Application Settings module in order to save the state into SharedPreferences (android) or NSUserDefaults (iOS) instead of LocaleStorage (default target in vuex-persist for web project).
- "Transpile" the module in TypeScript
- Refactor code and folder structure
- Make it a NativeScript plugin
- Add tests