Using following example:
https://github.com/zeit/next.js/tree/canary/examples/with-redux-wrapper
After page has been refreshed getInitialProps get called and store get populated with initial state. But only on a server side. When comes to client side store is empty and initial state is passed a prop. Is there a way to set store state with initial state again or what should I do?
You should use redux persist with this example
https://github.com/zeit/next.js/tree/canary/examples/with-redux-persist
Related
Is it possible to determine the last called action in an Angular/Redux project in the code so that I can react on it in the observer? Currently I am using a property in my redux store which is set to the current name of the action in the corresposonging reducer, but is there an easier way to do this?
Below is the flow of my app:
I have to fetch profile pics of creators of each posts in the list.
I have an action type FETCH_USER_PROFILE. The action contains userId to be passed to api call inside saga function.
Considering React application, the profile or Avatar component of the post dispatching the action based on the createdByUserId prop it receives from the parent post component.
I have a key in the reducer isFetchingUserDetails
whenever the action type FETCH_USER_PROFILE is dispatched, inside saga for it, I yield-put isFetchingUserDetails as true.
And when the response from api is received,I yield-put isFetchingUserDetails as false.
Based on isFetchingUserDetails I display the loader on Avatar component.
It works fine for one api call but when multiple dispatches of same action type is sent (with different userIds though) simultaneously, it modifies the isFetchingUserDetails continuously as api calls can take non-uniform time due to network constraints.
Due to this even for avatars or profile for which response is not fetched doesnot show loader because isFetchingUserDetails is set as true by the first response received.
Kindly suggest me what I can do in this scenario.
Should I make multiple action types with suffices as userId? Is this even possible?
Should I set isFetchingUserDetails suffixed with userId? But it would make multiple keys in reducers if the user count is 10k+
I have 2 simple aspx pages. On my default page, I have a simple label that's using ko.data-binding to a Session variable.
I thought if I change that variable KnockoutJS would update the user interface. When I click the button on sessionchanger page I changed the session variable that is being observed by ko. Where did I go wrong?
You have to change value of status property of viewModel instance to reflect changes on ui.
var vm = new viwModel;
ko.applyBindings(vm);
vm.status('new value');
You bind vm object to body not session object. You just use session object to initialize vm.status property.
So, you can't set new value in vm.status from the other page.
To be able to track it you should use client-server communication. It can be AJAX with polling functionality or WebSocket. So, you should check or listen server side and if any changes occur you can update vm.status property and after that it will reflect ui as you expect.
You cannot do it because asp.net rendering engine simply pass value of Session["target"] and not any link to that variable, also your knockout code isn't well written, see #Viktor Kukurba answer to get clearer idea of how to use and apply data-binding.
To achieve desired result you could use one of techniques listed below:
Preferable
Use WebSockets to notify your "Default" page about changing session variable by "Session Changer" page.
Take a look on tutorialBuilding real-time web apps with WebSockets using IIS, ASP.NET and WCF to get practical knowledge of how apply that techniques.
Workaround
As workaround you could get quite similar to required behaviour after applying next steps:
Create asp.net http request handler which would return value of Session["target"] in json format.
Create javascript function (let's call it refreshSessionTarger), which would send AJAX request to newly created asp.net http handler and update value of observable variable ( so knockout would reflect to that change, but note that you have to add ko data-binding properly).
Put refreshSessionTarger function created in step 2 into setInterval function as callback and set interval of how often in milliseconds refreshSessionTarger shall be executed.
function refreshSessionTarger(){
// perform ajax request and update variable which holds session target
};
var delay = 5000;
setInterval(refreshSessionTarger, delay)
I have a template which is a simple edit form. The _id of the document to be edited comes in a session variable (set by mini-pages from the URL: http://example.com/items/4zt4z3t3t). In the Template.editForm.createdfunction I try to get the correponding document from the collection using ItemCollection.findOne({_id:_id}). The _id is set correctly in all cases.
When I navigate to http://example.com/4zt4z3t3t and debug the created function, ItemCollection.findOne()returns undefined, although there are items in the collection. Therefore I can never find my item by _id. Also, when I move the item find procedure to the routing stage, there is also no result for the find. Later on, the colleciton works as expected.
Any pointers?
Meteor uses a Data on the wire principle. This means when your HTML has loaded your data isn't sent along with it, at least initially.
You can't therefore access data in a .created function, unless you expect that template to be loaded after the data has been downloaded. This is why it returns undefined initially but if you check later its there.
You can either, wait for a callback from the subscription on when the data is completed, then load the template.
OR
Use reactivity in your template and let it load empty, and automatically fill it up with data when the data has come in (really the easiest). Access your data in the template and use a handlebars helper to fill in the data and use the .rendered callback to do any changes after.
My action is inserting data from form into the database.
Now my problem is every time, user hits "refresh" button of browser, the action class is called with existing data and fresh new entry with the same database is made.
Is there any way to get refresh just refresh the data rather than calling the action class?
or at the minimum prevent 'refresh' on the page?
You have to use saveToken() method in action class and reset token values. which is available in Struts
You can use struts tokens- Prevent Duplicate Submission
http://www.techfaq360.com/tutorial/multiclick.jsp
and Always check for duplicate in database
I'm not sure if this is what you're looking for but see if serves as a starting point:
http://www.whoopis.com/howtos/jscript-refresh-save.php
As for the database entry problem, that should be taken care by your primary key of the database. If there's a pre-existing value for the same primary key, you shouldn't update!