Model-View-Presenter sample application in nodejs

I studied various MV * patterns and noticed that MVP is very heavily used in .Net applications but almost none. The only other large structure that seems to include it is the GWT, but only in some parts.

  • Why is MVP such a thing for Microsoft (why is it not so popular in other languages)?
  • Is there a nodejs application / project using MVP (preferably with a source that I can look at)?
+6
source share
5 answers

There were no great MVP examples in nodejs. We did some research and implemented the TODO application using the MVP template in nodejs and .net .

That is not all, but I think it fills the gap. Tensile requests are welcome.

https://github.com/EchoGlobalLogistics/mvp

+1
source

Talking about the reason that he is like Microsoft can be rooted in the design decisions of at least two large companies and their respective structures. Microsoft has included MVP in .NET. So far, Apple has chosen MVC in Cocoa.

As for JavaScript, take a look at the recent Riot.js framework https://moot.it/blog/technology/riotjs-the-1kb-mvp-framework.html

Although this is not particularly a “node.js framework”, it’s an example of something moving towards the term “Isomorphic JavaScript” (JavaScript level on the client server +), and what can be brought to the table, involving many engineers from many different events and experiences .

From this article:

Riot models define your application. This is your business logic, open to the outside world with a well-thought-out API. A fully isolated test module that can be run in the browser and server (node.js).

From my experience and please apologize for my general common expression, the reason MVP is not so visible in this technology is because many people either did not hear about it, did not forget about it, or simply did not see a big difference from that what is the "Controller" and what is the "Lead". This does not mean that there is no difference, and Tero Piirainen described the situation quite well in the Riot.js article for people who came from other JavaScript MVC frameworks.

+3
source

tl; dr Take a look at flatiron , especially in the CLI plugin. Also this article https://blog.nodejitsu.com/writing-cli-apps-with-flatiron and its sample section.

Answering your first question, I would say that MVP is not everything Microsoft has, even a Wikipedia article says that. It was the language developers at Microsoft who chose the paradigm of hiding widget implementation details.

When you interact with widgets as a user, a lot of things happen. And to some extent it may seem that the widget itself can be considered as a small application with its own model of business logic, with its own representation and controller. Recall, for example, a drop-down list: it has a set of methods to actually draw some rectangles on the screen, it also has methods for presenting a list of values ​​as text, and when you click on an element, the background color changes and text occurs according to certain rules (I think business logic). The Microsoft.Net platform has much in common with the user interface. That is why it is so important to choose the paradigm that is best suited for this purpose.

Node, on the other hand, is a fully backend platform, not a web application development environment. I am not saying that you cannot or should not create a web application with it. I want to say that the role of Node code in a web application should be limited to IO. Receiving requests, sending responses, sending / receiving data to / from storage, parsing is possible. And you can create a framework for building web applications on top of Node, of course.

Trying to follow MVP when building a web application, you probably want Presenter to be as close as possible to the actual rendering of the widgets. In the case of web applications that will be a browser. Node in this case will play the role of a REST server (or any other preferred way of exchanging data can be used instead of REST here).

There is another application class that Node can be used to create. These will be CLI applications. Here you can create applications using MVP and have a presenter in Node. To find examples, I would suggest looking at the flatiron framework website, which has good support for building cli applications, and also has some examples of such applications: https://blog.nodejitsu.com/writing-cli-apps-with- flatiron .

There is also https://github.com/mscdex/node-ncurses . This may give you the option to quit your own MVP. It is good practice when your goal is to research an item.

0
source

We recently used nodejs with an expression to create a web application. Working on this, we created a small frame on top of the express to better streamline our code. The structure forces you to write separate handlers (presenters) for GET requests and commands for POST requests. (See Martinfowler.com/bliki/CQRS.html). The framework also creates a Post-Redirect-Get template (en.wikipedia.org/wiki/Post/Redirect/Get), allowing only redirects from commands. Npm package - expressmvp ( https://www.npmjs.org/package/expressmvp ).

0
source

You can definitely use MVD-style Node. Here are some really good questions / answers that I used as a guide when structuring my applications:

How to structure express.js application?

ExpressJS How to structure the application?

There are several frameworks for Node that are based on MV *:

  • Matador
  • New Sails.js (based on Rails)
  • Most Node frameworks are built on Express.js , which can be adapted as MV *, as described in the answers above.

Here is an example application built on pure MV * style expression.

-1
source

Source: https://habr.com/ru/post/947481/


All Articles