Unobvious model change - scope

In a angularjs/express/postgres app, i want to load big list of json object from the db to the client.
Each json object is it's self pretty big. Each on is stored in a separate row.
So i want to display each json object as soon as they are read from db.
I've found the EventSource api, to progressivly send the json object from server to client.
Which works fine.
Then i want to display them on my view as soon as possible.
Working with event source include working with event listeners.
As explain here https://groups.google.com/forum/?fromgroups=#!topic/angular/xMkm81VkR9w
the angular won't notice the change of the model since the scope modification occurs outside the angular world, inside a event listener.
There is a way to trigger to dirty cheking by calling $scope.$apply().
But since my list as more than 200 element, this error is triggered:
Error: 10 $digest() iterations reached. Aborting!
So i'm wondering if there is another way to trigger the dirty checking ? Maybe another way to approch my issue.
EDIT:
The title was changed after reflection on the real problem

In fact the issue come from the partial, where i add filter expression in a ng-show directive
My bad

Related

Mongoose middleware disable(/unhook/delete/remove) created hooks

In an express/mongoose server application, I want to receive a request, then change state to one which can receive another type of request, and when the second request completes successfully I want to respond to the first one.
The way I've implemented this is to use a placeholder document in MongoDB, and set a mongoose post save hook upon receiving the first request. This async middleware is a closure which holds a reference to the response from the first request.
The second request modifies this placeholder document with new information from another remote client. Upon saving this, the post save hook gets run, which determines if this is the correct document, and validates the change w.r.t the first request. If that passes, the first response is sent. Otherwise, the hook continues waiting for the correct change, checking all the saves that happen to that schema.
My problem is that even after the correct and accepted changes happen and the response is returned to the first client, the (shell) post-save hook still remains. Now, this does return instantly upon seeing that the response has been sent successfully, but it bothers me that it still exists and gets called for all saves.
This is an application that's meant to run with an anticipated 1k-10k such requests over its lifetime. So unless the application is periodically restarted, we might see a significant slowdown from all the post-save hooks getting called.
Now, onto the questions:
Is there a better/easier/straightforward architecture to solve this problem?
If not, should I be worried about all the shell post-save hooks for this use case?
If so, how do I delete a freaking hook?
This is a far more infuriating issue than usual with this sort of thing because of the existence of 'remove' hooks. All the search engines fail to actually point me to disabling/deleting/unhooking/removing middleware functions. Nothing in the docs either.
The best I can come up with is to use a single-argument middleware function, and then overwrite that function with {} or undefined (or another closure function if we encounter another request-type-1). Is this the only solution? With this, I lose the ability to make and retain responses of multiple request-type-1s.
Found two methods of doing this, one from this answer to delete specific entries in the call queue of the schema.
EDIT: The following doesn't work with Mongoose as of 5.1.5 - removePost isn't defined.
The other (better) one was found when perusing the codebase used to implement hooks.
You can remove a post by using
Document.post('set', someFn); // Setting it
Document.removePost('set', someFn); // Removing it

Server-side rendering with Node/React. How do I fetch the data?

My goal is to server-side render my blog built with Node and React/Redux. I am following this tutorial, and using this project as an example.
I have loaded my components, created an empty store, successfully used this stuff to render and return html pages.
My remaining challenge is to figure out how to fetch the inital data so that I could put it into the store. I am assuming, I somehow need to tell the store(on the backend) to dispatch the actions that will fill it with data.
This example is using this function, that seems to be telling the store to dispatch actions, and returns the store filled with data(?). But it flies way over my head, I don't get how it works, and when I copy the code, the store still returns empty.
Can you help me to understand how this is supposed to work? What do I need to do to tell the store to execute actions, that will go to my API, fetch data, and put it into the store?
basically fetchComponentData will dispatch actions while server rendering, like the document says
fetchComponentData collects all the needs (need is an array of actions that are required to be dispatched before rendering the component) of components in the current route.
where need is an array of functions that return a redux action, which defined inside each smart components (connected with redux store and react-router)
for example, in mern-starter, when you visit index route, it'll render this component and there is the need method which will be executed by fetchComponentData when server rendering.

Orchard CMS: Invoking two actions leads to duplicate notifications

Our Orchard application displays two of all notifications that are added to the notification service. So far we have traced the problem and know what is causing it, but are looking for a solution other than the obvious, for reasons I shall now elaborate.
So we are using a number of themes to render our Orchard based application. Within our layout, we have a Razor call to draw a header bar that displays a set of information about the user that is logged in.
#Html.Action("OutOfGameHeader", "Options", new { area = "Area.area.Location.Common" })
This action calls the OnResultExecuting() method in Orchard.UI.Notify.NotifyFilter which (among other things) populates the Messages Zone with the current set of notifications. When we make the call the render the Messages Zone, this same method runs again and the notifications are added to the Zone's shape again resulting in duplicate notification being displayed when the Zone is actually drawn.
Can anyone think of a solution that meets the following criteria:
Drawing the header without calling #Html.Action() to avoid OnResultExecuting() being triggered the first time.
Without creating a new Widget in a new Zone as this would involve us changing the manifest for dozens of existing themes to include it.
We also found this just below the point in the code where the notifications are added to the Zone, so if anyone knows anything more about it, that would be helpful too.
//todo: (heskew) probably need to keep duplicate messages from being pushed into the zone like the previous behavior
//baseViewModel.Messages = baseViewModel.Messages == null ? messageEntries .Messages.Union(messageEntries).ToList();
//baseViewModel.Zones.AddRenderPartial("content:before", "Messages", baseViewModel.Messages);
Any thoughts greatly appreciated.
Avoid Html.Action. This runs through the whole lifecycle as if this was a new request. That you think you need it is often a sign that you need to refactor and extract that logic that you want to re-use out of your controller. In Orchard, it's also better to use dynamic shapes.

JSF: How to capture response that is send to client

I want to implement some kind of help-functionality within my jsf-application
Scenario:
When the users of my app are having problems, they send me screenshots. These are of poor quality and I cannot see the information I want.
My idea: I add a "help"-Button into my jsf-Page. When this button is pressed I store the render-response (resulting html) that is send to client on my hd.
Now I can open that generated html-file and can see the information I want (e.g. values of inputfield)
Now my Question.
How can I perform this task?
I have tried PhaseListener and using
PrintWriter w = new PrintWriter(System.out);
DebugUtil.simplePrintTree(FacesContext.getCurrentInstance().getViewRoot(),"",w);
but this is just the component tree and not the resulting html
In other words: I want to capture the output of FacesContext.getExternalContext().getResponse() that is send to client
any ideas?
Use a Filter around the FacesServlet. There define a HttpServletResponseWrapper and in turn make its getOutputStream() and getWriter() return wrappers of the original objects. In the wrappers, in addition to delegating to the original implementation, store the written data somewhere else.

Reverting CoreData data

I have an NSTableView which is populated via a CoreData-backed NSArrayController. Users are able to edit any field they choose within the NSTableView. When they select the rows that they have modified and press a button, the data is sent to a third-party webservice. Provided the webservice accepts the updated values, I want to commit those values to my persistent store. If, however, the webservice returns an error (or simply fails to return), I want the edited fields to revert to their original values.
To complicate matters, I have a number of other editable controls, backed by CoreData, which do not need to resort to this behaviour.
I believe the solution to this problem revolves around the creation of a secondary Managed Object context, which I would use only for values edited within that particular NSTableView. But I'm confused as to how the two MOC would interact with each other.
What's the best solution to this problem?
The easiest solution would be to implement Core Data's undo functionality. That way you make the changes to Core Data but if the server returns the error, you just rollback the changes. See the Core Data docs for details.

Resources