I have a users list and I want to be able to update each user's details (in a modal) and keep them in the state(no API call for update). I'm trying to do this with effects but I'm not sure what is the correct way to achieve it.
Actions:
Reducer:
User details
You don't need an effect if you don't need to make an API request (or if there's no side effect).
In your case, the modal dispatches an action, and the reducer listens to that action and updates the state.
Related
There's already a question similar to mine, but it doesn't tackle my problem.
I'm trying to set the google tag manager to track login events in my website.
But I can't identify the action related to the login event on the tag assistant.
Here is a print of the actions when I login:
None seem to be strictly related to the login event.
I tried to track some of these actions, but they occur in many other actions.
(thus, I collect data I don't need, as if they were login events)
What of these actions is related to the login event?
How can I precisely identify the login action ?
You can automatically implement data layer events on form submissions with ListenLayer.com. In this case, you will likely need to use their Custom Forms Listener.
You have to create an account, place their script on your website, enable the Custom Forms listener and it's features and then identify your forms under the Listener's event settings. You would do this by writing a simple rule to match the CSS class, ID, or form Name element etc. (these things would exist in the <form> tag.
Here you can see I have set some rules to identify a form like this
<form class="form-container"> or <form class="listenlayer">
Publish and test on your website.
Now, when the form is submitted, the Listener will automatically push data into the data layer identifying the form and the action.
From there you would use GTM to register and read the data layer activity. I assume you know how to do that since you have the GTM debug view going, but basically you'll get a new message on the left side with an event name and you can create a Custom Event trigger in GTM and also register Data Layer Variables to use in your trigger. It's all down hill from there!
With tracking you are usually left out with two approaches :
Either you ask your developer to implement a dataLayer event on a specific action / interaction so that you can then use this as a "custom event" trigger in GTM. For instance, here, on the login success page, after the GTM snippet, the developer could invoke the following code:
dataLayer.push({ event: 'login' })
That will allow you to use 'login' as your event name in GTM custom event trigger.
As you began doing, if your developer cannot implement it, you may try to identify variables that will help you isolate that specific action / page. For instance here, maybe does your successful login page has a specific URL you could use in a page view event, targeting that specific page path.
I need something like the viewRender event in order to persist the user's state. I'm building a UI where users will frequently jump in and out of the calendar, so preserving their view/range is essential for a pleasant experience. Does this exist in v5? The last mention I can find of it is from v3.
The only workaround I can think of right now is a direct click handler on every view control element, or a very heavy-handed MutationObserver. This is a React app so either one is going to be super awkward.
Thank you!
Edit 2021-02-11:
I looked at the available view render hooks but none of them address my problem. What I need is an event that will fire whenever the view state changes, including clicking between weeks/months/etc., so that I can persist the date range the user most recently viewed as well as the view they had selected.
viewDidMount is the closest to what I need, but it does not fire when the date range changes.
Edit 2021-05-26:
Another problem with using viewDidMount is that using it to enact side-effects is a bit overeager. The hook gets called whether or not the user has actually done anything, and the default view always gets passed as view inside the View Object. So there's no way to tell whether this mount event contains data I should persist or not.
I am trying to send data from one ViewModel to another using Messaging Centre.
I have subscribed the event in 2nd ViewModel's constructor. But the event is not subscribed as the constructor is not compiled until I open the page/view corresponding to the ViewModel.
I am using MVVM Light, until now I had an understanding that the VM's constructor are compiled when ViewModelLocator is called at the app startup.
Can someone help me understand this better and how can I subscribe the event i.e. compile the constructor without the VM being called.
Perhaps you are thinking about this in the wrong way. Without seeing code it's difficult to see what you are trying to achieve exactly, but what you could do is subscribe to the event elsewhere in your app, for example in your App.xaml.cs. When the event fires, at that point navigate to a new page of type ViewModel2 and pass any details required as a navigation parameter.
I'm writing a realtime updating graph using Angular2. My graph is being updated through data coming via an http observable, and a setInterval command.
A weird thing I've noticed is that, when I route through angular to a different view on my app, the setInterval command on the previous component does not stop, causing the server for unnecessary load.
What would be the correct method to stop setInterval http requests on route changes in Angular2?
Any help would appreciated.
Events are managed very differently by browsers, basically they are processed by Event loop.
The browser has inner loop, called Event Loop, which checks the queue
and processes events, executes functions etc.
So whenever you add any asynchronous event like setTimeout/setInterval, they gets added to Event Loop with their handlers.
Basically whenever you wanted to stop/de-register those asynchronous event, you need to de-register them manually. Like here you need to call clearInterval method with that setInterval object reference, then only it will remove that async event from Event Loop.
You could use ngOnDestroy life-cycle hook where you can have your stuff before destroying your component.
//hook gets called before Component get destroyed or you can say disposed.
ngOnDestroy(){
clearInterval(intervalReference)
}
Extra stuff(Comparing with Angular 1)
The same kind of problem you can see in any Javascript Framework. In Angular 1 there is way to handle such kind of situation(I'm adding this stuff so that anyone from Angular 1 background can easily get this concept by comparing A1 with A2). While destroying controller instance angular internally emit's $destroy event over element & $scope of that element. So by having listener over $destroy event, we used to do stuff to ensure those object value/object/events should not available.
$scope.$on('$destroy', function(event){
//do stuff here
})
element.bind('$destroy', function(event){
//do stuff here
})
I have a Web API service that I have managed to use to pull values into a ContentPart by using the method outlined here: How to change Orchard record repository.
Now, what I want to do is update the values of the properties on my ContentPart and have the update performed via a Web API call. I think I'm close, but just can't get an update method to fire.
In my Handler, I have added a handler for OnUpdate. I can see my OnUpdate method get registered, but it never executes.
So my question is: Is this the correct handler event to use? And if so, how can I get it to trigger?
I should add that I am accessing the ContentPart through a Controller, as opposed to a Driver.
OnUpdating / OnUpdated get fired whenever you call IContentManager.UpdateEditor(item). In the default scenario this happens when you hit "Save" button when editing your content item.
I don't quite get what you mean by "accessing the ContentPart through a Controller"?
Do you have a custom controller that handles the item editor rendering and it's postback?
Or are you creating and updating some items in code, without using the built-in editors at all?
In the former case, you need to ensure that
IContentEditor.UpdateEditor(item) gets called for the whole content
item inside the POST action (same way it does in the default
controller - Core\Contents\Controllers\AdminController.cs).
In the latter, which I guess might be the case here, OnUpdating /
OnUpdated won't be fired and you need to call the web service on
your own from the controller action, as Bertrand pointed out in the comments.
There is also a third option available and I found it particularly useful in similar cases:
Use LazyField<T> as a backing field for those part properties you need to push to web service after update.
Put the code that calls web service inside that lazy field's setter (set this up during handler OnActivated event).
Now, whenever your property gets updated, a call to web service will be made, ie. the lazy field will act a a transparent proxy between your web service and current code.
For examples how to work with lazy fields take a look into CommonPartHandler class and methods LazyLoadHandlers and PropertySetHandlers.