使用虚假的即发即忘数据加载 Meteor 客户端应用程序 [英] Loading a Meteor client app with fake fire-and-forget data

查看:49
本文介绍了使用虚假的即发即忘数据加载 Meteor 客户端应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找出一种好方法来创建使用 Meteor 应用程序的教程.从视觉上看,我想出了一个很好的方法,并将其打包成一个智能包:

I'm trying to figure out a good way to create tutorials for using Meteor apps. Visually, I've figured out a good approach, and packed this into a smart package:

https://github.com/mizzao/meteor-tutorials.

然而,事实证明还有第二个部分很难弄清楚.

However, there is a second piece that turns out to be rather hard to figure out.

在许多情况下,教程应用需要加载虚假数据,以向用户展示界面,而无需填充可能难以生成的真实数据.(例如,请参阅 https://www.planapple.com/trip/demo/349/ 这是 PlanApple 的演示).在 Meteor 中,由于应用程序的内容基本上是由一些集合的内容定义的,因此我看到了两种方法:

In many cases, a tutorial app needs to be loaded with fake data, to demonstrate the interface to the user without requiring it to be populated with real data that may be hard to generate. (For example, see https://www.planapple.com/trip/demo/349/ which is a demo for PlanApple). In Meteor, since the content of an app is basically defined by the contents of some collections, I see two ways to do this:

  1. 维护两组集合,一组用于教程,一组用于实际应用.在教程中使用第一组,在用户实际使用应用时使用第二组.
  2. 使用一组集合,并在教程期间使用订阅填充虚假数据,并在用户使用不同订阅实际使用应用时填充真实数据.

第一种方法显然不好;这意味着人们无法在不知道它是否被用作教程的情况下编写应用程序,并且在呈现应用程序时有很多混乱的 if/else 反应性逻辑是不必要的.此外,如果应用程序有多个集合,这将很难维护.

The first approach is clearly bad; it means that one cannot write the app without being agnostic to whether it's being used as a tutorial or not and there is a lot of messy if/else reactive logic in presenting the app that is unnecessary. Moreover, this will be very hard to maintain if the app has more than a few collections.

第二种方法似乎是更像 Meteor 风格的做事方式.我们基本上想要的是服务器发布用一些虚假数据填充所有客户端集合,然后允许在客户端以任何方式操作数据,而不会将更改传播到服务器;客户端基本上获取服务器教程数据的副本,然后仅对其进行本地更改,然后将其丢弃.这归结为两件事:

The second approach seems to be the more Meteor-esque way to do things. What we basically want is for a server publication to fill all the client collections with some fake data, and then allow the data to be manipulated in whatever way on the client side without the changes propagating to the server; the client basically gets a copy of the server's tutorial data and then makes only local changes to it which are then discarded. This boils down to two things:

  • 通过自定义订阅将虚假数据从服务器发送到客户端,并将其发送到与常规应用程序相同的命名集合中.正如我在 https://stackoverflow.com/a/18880927/586086 中所写,这绝对是可能的

  • Sending fake data down from the server to client via a custom subscription into the same named collections as the regular app. This is definitely possible as I've written in https://stackoverflow.com/a/18880927/586086

在初始加载数据后忽略来自客户端(在服务器上)的任何插入、更新和删除;但允许它们在本地发生.如果创建空(未命名)集合,这也是可能的,如 http://docs.meteor.com/#meteor_collection.

Ignoring any inserts, updates, and deletes from the client (on the server) after the initial load of data; but allowing them to happen locally. This is also possible if one creates null (unnamed) collections, as in http://docs.meteor.com/#meteor_collection.

问题是,虽然可以分别执行上述两个步骤中的每一个,但我想同时执行这两个步骤 - 我希望将数据加载到与客户端使用真实数据相同的命名集合中,以便避免具有两组集合的复杂控制逻辑,但我也希望更改仅限本地,但不会在教程期间通过订阅传播回来.

The problem is that although it's possible to do each of the two steps above separately, I want to do both of them - I want the data to be loaded into the same named collections as the client would have with real data, to avoid the complicated control logic of having two sets of collections, but I also want changes to be local-only but not propagated back over the subscription during the tutorial.

有人知道如何做到这一点吗?

Anyone have ideas about how to do this?

关于第二部分是否可行的相关问题:Meteor 数据库 mutator 如何知道它是否是从 Meteor.method 调用的与普通代码相比?

A related question about whether the second part is possible: How does a Meteor database mutator know if it's being called from a Meteor.method vs. normal code?

似乎我们在本教程中基本上想要做的是直接插入本地 Meteor 集合,如 {https://stackoverflow.com/a/19523301/586086}.但是,有没有一种方法可以在教程中为所有相关的修改器打开这种行为,而不是显式地指定它?

It seems that what we'd basically want to do in the tutorial is inserting directly against the local Meteor Collection as in {https://stackoverflow.com/a/19523301/586086}. However, is there a way to generally turn on this behavior during the tutorial for all relevant mutators, instead of explicitly having to specify this?

推荐答案

我最终通过 partitioner 包,它允许将连接的客户端分成不同的切片,每个切片包含不同的数据.

I ended up implementing this myself with the partitioner package, which allows connected clients to be divided up into different slices each containing different data.

基本上,这个想法是在用户在教程中时将他们放入一个新分区,然后在他们真正使用应用程序时将他们放入另一个分区.也适用于 tutorials 包.这放弃了在客户端本地进行更改的能力,但存储教程数据不会有太多开销,而且无论如何对我来说都是有用的.

Basically, the idea is to put the user(s) into a new partition when they are in the tutorial, and then put them into another partition when they are using the app for real. Works great with the tutorials package as well. This gives up the ability of having changes to be client-local, but storing the tutorial data doesn't have much overhead and turned out to be useful in my case anyway.

执行此操作的应用示例是 https://github.com/mizzao/CrowdMapper.

An example of an app that does this is https://github.com/mizzao/CrowdMapper.

这篇关于使用虚假的即发即忘数据加载 Meteor 客户端应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆