I have a Sencha Touch App that loads data from a REST service into a store using a REST proxy. The load event of this store also copies the records into a localstorage store. This is because the app needs to work in an offline mode. I am trying to write back changes made to records in the localstorage to the REST service, but haven't managed to figure out how to sync the localstorage store and the store that uses the REST proxy. Any ideas?
I followed the example given here http://www.sencha.com/learn/taking-sencha-touch-apps-offline/ , but it covers only read-only scenarios for offline data.
You'll need to implement something similar in the save event on your localstorage store that copies changes over to your onlineStore (much like you're copying new items from your onlineStore to the offlineStore when it loads).
#Lyle Pratt is correct about having a functionality that copy from your "offline" store to your "online" store. But to expand it more, I will create a function inside your offline store where it will save or copy your offline data to your online store.
Ext.define('MyProject.store.OfflineMessage', {
config: {
model: 'MyProject.model.Message' //this should be the same with your online store
},
sync: function(){
var me = this,
onlineMessageStore = Ext.getStore('OnlineMessage'), //you can get your current store or just create a new one
items = me.getData().items;
onlineMessageStore.setData(items);
onlineMessageStore.sync();
}
});
On the other hand, you can also create a same functionality for your online store wherein it will save your online data to your offline store.
Related
As of now, my app contains an array and the user can manipulate the order of items in it by dispatching actions. I'm using redux persist and even if I directly change the array elements by editing the source file, the array does not update unless I clear the app cache.
What are my options to update this kind of persistent data after I publish it to the store without forcing users to clear the cache?
What are you looking for is migrations.
How it works:
Load user's previous state from local storage on app start
Update fields you need
Here is a setup example
I'm using Nuxt 2.15 with target: "static" and hosting on a shared hosting "hostinger". I fetch the data from an external API using axios and Vuex state management and here comes the problem where the app doesn't load the new data it gets from the API.
How can I make the app rerenders its data and output the newly updated data it gets from fetching the API?
I assume you are using nuxtServerInit or asyncData for getting the data from API. This used with static mode means that data is get only during generation. Which is great for not too often updated content because it doesn't have to connect to server every time it's faster.
Depend on your needs you can:
Get data from API in mounted() hook this will get data from API every time the page is loaded BUT it also means that it could be loaded with some delay and it probably wouldn't be indexed by search engines
You can go with universal mode (https://nuxtjs.org/docs/configuration-glossary/configuration-mode/) and start your site on node.js server which will use up-to-date data from API each time user will open your site.
EDIT: as #kissu corrected me in comment this one is deprecated, please use this one: target:'server' instead of target:'static', which is default so you can just remove this line (https://nuxtjs.org/docs/configuration-glossary/configuration-target/ )
I'm building a simple app where that shows product recommendations.
I want to make it possible for the client to choose how many products he'd like to display, like from 5 or 20 with a liquid variable called {{NofProducts}}
I'm using the shopify app example, there are two important pages:
pages/index.js <- here the client can write inputs
theme-app-extension/block.liquid <- here we write a liquid code that will be appended to the page.
How do I pass the inputs from index.js to the block.liquid?
Do I have to store it elsewhere in a database for each user?
Do I have to create a file using graphQL inside each theme with the user choices using "createScriptTag"?
Ok, unfortunately every Shopify tutorial is extremely confusing for beginners.
They way you pass the store owner inputs to the app is using a database, I did it using Redis, but you can use MongoDB or maybe even a local file, but that's not ideal.
You should not store the user inputs inside their theme, because each time you access or modify a file in the customer's store, you need to use their getSessionToken function and make a new request using the token, while using your database you just need to get the session ID using SESSION_STORAGE.
I have a ReactNative app that is working with some constants,
export const BEARER_TOKEN = 'eyJhbGciOiJIU***'
The app works fine until I need to update the token so with a new version distributed by appcenter,
If I just update the app, it keeps the old token
but
If I delete and install a new version, the new token is used
So, how can I make sure that the new token gets loaded? like if the app starts reload constants?
Thanks.
I suggest using Asyncstorage and Redux state in order to maintain your Bearer_Token.
For instance, assume using the Facebook app.
You are logging in for the very first time. Capture and store your Bearer_token in Asyncstorage and also maintain in the redux state.
Next time when you kill the app and open again. Load the Bearer_Token from Asyncstorage.
Your Bearer_Token will be set dynamically.
You can't, with this approach. This is the nature of javascript, it loads everything initially and even if you change it by putting the variable in object. It is a bad practice.
The better approach is to use redux or context api,
I see you want to use BEARER_TOKEN, for user authentication probably.
So you can have a state, authUser inside your redux and it will keep track of the token in your entire app. This approach is very useful when you want the user to logout if any change in authToken.
https://redux.js.org/
For a simple version, you can use context api from react.
now the third option, If you really really really want to not use these approaches.
You can just usewindow.token = 'sdfasdf';
then whenever you want to change it, just use window.token = 'soemthing else'from other files.
My app is similar to facebook.
I want to retain the userID/Username upon login screen, so that i could use it at rest of the application for queries online data.
I tried storing it in a javascript object after successful login, but it gets washed away when i move to other screens.
Thanks
You can use the App.Properties API.
Example, right from the docs.
Titanium.App.Properties.setString("my_prop","cool");
if(Ti.Facebook.loggedIn) {
if(Ti.App.Properties.hasProperty('fbid')) {
var fbid = Ti.App.Properties.getString('fbid');
}
}
You can use the hasProperty to verify they have logged in in the past and when they do logout you can use the removeProperty so that your app assumes they haven't logged in and starts over.
If you are going to store the information in the properties, you should be aware that the is information persisted on the device.
The use of properties for short term storage IMHO should be avoided if possible.
You have two choices, one store your variables in the Titanium namespace
Titanium.App.credentials = { "user" :"username", "pwd":"password123"};
Or create your own namespace and store your variable there. This will ensure you values are available throughout the application, but not stored on the device.
There is an example on my blog here http://blog.clearlyinnovative.com/post/6519148138/titanium-appcelerator-quickie-global-variables-scopes