I used "'socket-io-client'" in my project. I want receive message in "'vue js'" so i want use Observable method to Observable upcoming message.
Related
I am using Laravel 9, Jetstream, Inertia, Vue 3.
I have created an Api Resource for my Model Project
$projects = ProjectResource::collection(Project::get());
return Inertia::render('Project/Edit', compact('projects'));
In Vue, in the props "project" i get a nested array "data" and only the objects I need are already in it.
projects: Reactive
data:Array[2]
0:Object
1:Object
And it should be like this
projects:Reactive
0:Object
1:Object
I don't want to access props in vue via "projects.data"
I want it to be: "projects"
How to achieve this?
Taken from the official laravel docs (Data Wrapping)
By default, your outermost resource is wrapped in a data key when the resource response is converted to JSON.
In order to turn off this behaviour:
If you would like to disable the wrapping of the outermost resource, you should invoke the withoutWrapping method on the base Illuminate\Http\Resources\Json\JsonResource class.
So basically you need to run:
JsonResource::withoutWrapping();
In the boot method of your AppServiceProvider.
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?
How do I get context from Activity in a fragment in Kotlin. I know, in Java you can call getActivity()
To get the Context in the Fragment from AndroidX support library you can use method requireContext()
If you need an Activity instance to which your Fragment is attached, use the requireActivity() method.
Note: These methods will only work when the fragment is attached to some activity. Otherwise they will throw an error.
Could you please more elaborate into the following questions ??
1 - react-redux is already provides the
connect(mapStateToProps, mapDispatchToProps),
Then why there is use of middleware and redux-thunk,As per my
understanding this connect function would suffice to get the
state from the store and dispatching the events from the
component?
With plain Redux functionality, your action creators must be plain object and hence you cannot make async calls in action creators or dispatch multiple actions from one action creators, middlewares are useful here
According to the docs:
Middleware is the suggested way to extend Redux with custom
functionality. Middleware lets you wrap the store's dispatch method
for fun and profit. The key feature of middleware is that it is
composable. Multiple middleware can be combined together, where each
middleware requires no knowledge of what comes before or after it in
the chain.
The most common use case for middleware is to support asynchronous
actions without much boilerplate code or a dependency on a library
like Rx. It does so by letting you dispatch async actions in addition
to normal actions.
redux-thunk lets the action creators invert control by dispatching functions. They would receive dispatch as an argument and may call it asynchronously. Such functions are called thunks. Another example of middleware is redux-promise. It lets you dispatch a Promise async action, and dispatches a normal action when the Promise resolves.
You might look at the following example to understand how to use redux-thunk to make async calls
I am in reference to the router-store ngrx project (https://github.com/ngrx/router-store).
I am not clear how to use this project...
For instance let's take the following sample from the project documentation:
store.dispatch(go(['/path', { routeParam: 1 }], { query: 'string' }));
Is this meant to be use as a replacement to the angular 2 router: router.navigate(['/path...?
...or should I use the ngrx router-store only in certain circumstances? (if so which ones?)
Also what happens to the ngrx router-store when a angular 2 router html link e.g. <a routerLink="/heroes" is clicked?
More generally, can someone please explain what is achieved by the ngrx router-store project as compared to using the plain angular 2 router?
Or to rephrase, what does ngrx router-store brings in addition to the angular 2 router?
Edit: An interesting source of information and samples about ngrx is of course the ngrx example-app (https://github.com/ngrx/example-app).
I found a dependency to the router-store there but I have not been able to find where the router-store is used within the app...
FYI, here is the comment to be found in the example app about the router store:
#ngrx/router-store keeps router state up-to-date in the store and
uses the store as the single source of truth for the router's state.
The #ngrx/router-store exists so that it's possible for the store to be the single source of truth for an application's routing state.
Without it, there would be application state - the current route - not represented in the store. That means time-travel debugging using the DevTools would not be possible, as there would be no state in the store representing the route and there would be no actions representing route changes.
The router-store does not replace the Angular router; it just wires up listeners for routing actions and for the router itself.
When you emit a routing action using the go action creator, a "[Router] Go" action containing the specifed path is heard by the router-store which then calls the corresponding router method. When the router-store hears - from the router - that the route has changed it emits a "[Router] Update Location" action representing the route change and that action sees the router state in the store updated.
If, instead of using the go action creator, a routerLink is used to effect a route change, router-store will hear the change and will emit a "[Router] Update Location" action that will see the store's router state updated.
So, whether the route is changed via actions or more traditional links, the store always contains the router state.
With the "[Router] Update Location" actions representing route changes, you can undo said route changes via the DevTools - something that would not be possible if the router state were not represented in the store.
If you've not used the Redux DevTools, I would recommend you check them out:
Redux DevTools Extension
#ngrx/store-devtools
#ngrx/store-log-monitor
An example.
Say you have a selected id that you pass in the router state. That id references a customer.
Your url looks something like this: myapp.com/customers/7755664
When you route to the customer edit view, you can write a selector that gets the customer entity using the id from the router state. Say you want to scroll through the customers. You navigate to myapp.com/customers/7755653. The selector returns the customer, the select call emits and your view rerenders with the new customer.
It simplifies selectors and replaces the need to have a selectedcustomer property in your state.