简体   繁体   English

流星js:分离前端和后端

[英]Meteor js: separating front end from back end

So the whole point of meteor js is to allow the user to code the whole stack at once, but if I were working on one of the older frameworks like django , could I borrow the front end code from meteor js ? 因此, meteor js的全部目的是允许用户一次对整个堆栈进行编码,但是如果我正在使用django等较旧的框架之一,我可以从meteor js借用前端代码吗? For example, the front end syncing of the database, the templating, or how meteor handles events with the template, etc. 例如,数据库的前端同步,模板或流星如何使用模板处理事件等。

Is there a way to extract meteor js front end code to be used in an another framework? 有没有一种方法可以提取meteor js前端代码以在另一个框架中使用?

No, there's no such method. 不,没有这样的方法。 The whole point of Meteor (well, one of key points at least) is to have one framework that works both on front end and back end. Meteor的重点(至少是关键点之一)是要有一个在前端和后端均可工作的框架。 That way you don't have to write two separate logic layers, nor additional layer for communication between them. 这样,您不必编写两个单独的逻辑层,也不必为它们之间的通信编写附加的层。 It's a really big advantage. 这是一个很大的优势。

That said, you could theoretically use Meteor front end with django back end, provided that you talk to the server manually with AJAX and wrap the data with your own reactivity. 就是说,如果您使用AJAX手动与服务器通信并使用自己的反应性包装数据,则理论上可以将Meteor前端与django后端一起使用。 However, you'll end up rewriting a large part of Meteor yourself. 但是,您最终将自己重写Meteor的很大一部分。 It'll be much easier to either rewrite the old django code in Meteor, or use a dedicated front-end framework like Backbone. 在Meteor中重写旧的django代码,或使用专用的前端框架(如Backbone)会容易得多。

You can use Django DDP to provide a Meteor backend from your Django project -- including realtime, latency-compensated publications/subscriptions and remote procedure calls (RPC). 您可以使用Django DDP从Django项目提供Meteor后端-包括实时,延迟补偿的发布/订阅和远程过程调用(RPC)。 Have a look at the examples in the README and in the examples in the repo for inspiration. 请查看自述文件中的示例以及回购中的示例以获取启发。

DISCLAIMER: I'm the author of django-ddp. 免责声明:我是django-ddp的作者。

You could make it work. 您可以使其工作。

If you write a DDP server that talk to the Meteor front end. 如果编写与流星前端对话的DDP服务器。 And you could publish whatever data you want through DDP to a client only collection. 然后,您可以通过DDP将所需的任何数据发布到仅客户端集合。 (here is a link on how to https://www.eventedmind.com/tracks/feed-archive/how-to-publish-to-a-client-only-collection ). (这是有关如何https://www.eventedmind.com/tracks/feed-archive/how-to-publish-to-a-client-only-collection的链接)。

And on the front end you just need to use DDP.connect(server URL) to connect the server. 在前端,您只需要使用DDP.connect(server URL)来连接服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM