sails.io.js - nodejs - Resourceful PubSub没有收到模型事件(sails.io.js - nodejs - Resourceful PubSub not receiving model events)
我正在尝试订阅一个nodejs应用程序来模拟sails中的事件。 这是我的代码:
var socketIOClient = require('socket.io-client'), sailsIOClient = require('sails.io.js'); var io = sailsIOClient(socketIOClient); io.sails.url = 'http://localhost:1337'; io.socket.on("agent", function(event) { console.log(event); }) io.socket.get("/agent", function(resData, jwres) {})
当客户端(nodejs)连接时,以下是sails服务器上所有输出的链接:
https://gist.github.com/CiscoKidxx/e5af93ebcc24702ba4f8
我的理解是,当我创建一个新的代理时,它应该触发一个列出更改的console.log(event)。 这没有发生。 脚本启动后,我确实收到了“现在已连接到风帆”。 有什么想法吗?
这里是我的电话在我的UserController中创建一个新的代理:
Agent.create({ syncToken: token, owner: user.id }).exec(function (err, newAgent) { Agent.publishUpdate(newAgent.id, {syncToken: newAgent.syncToken});
I am trying to subscribe a nodejs application to model events in sails. Here is my code:
var socketIOClient = require('socket.io-client'), sailsIOClient = require('sails.io.js'); var io = sailsIOClient(socketIOClient); io.sails.url = 'http://localhost:1337'; io.socket.on("agent", function(event) { console.log(event); }) io.socket.get("/agent", function(resData, jwres) {})
Here is a link to all of the output on the sails server when the client(nodejs) connects:
https://gist.github.com/CiscoKidxx/e5af93ebcc24702ba4f8
My understanding is that when I create a new agent it should trigger a console.log(event) which lists the changes. This is not happening. I do get a "now connected to sails" upon script start up. Any thoughts?
Here is my call to create a new agent in my UserController:
Agent.create({ syncToken: token, owner: user.id }).exec(function (err, newAgent) { Agent.publishUpdate(newAgent.id, {syncToken: newAgent.syncToken});
原文:https://stackoverflow.com/questions/33926792
最满意答案
您可以创建一个也实现IPay的包装类,并让它捕获所花费的时间。
public class PayWrapper : IPay { private readonly IPay _wrapped; public PayWrapper(IPay wrapped) { if (wrapped == null) throw new ArgumentNullException(nameof(wrapped)); _wrapped = wrapped; } public void DecreasePay() { Stopwatch sw = new Stopwatch(); sw.Start(); _wrapped.DecreasePay(); sw.Stop(); Console.WriteLine(sw.Elapsed); } public void IncreasePay() { Stopwatch sw = new Stopwatch(); sw.Start(); _wrapped.IncreasePay(); sw.Stop(); Console.WriteLine(sw.Elapsed); } }
然后当一个类得到一个IPay时,它可以像这样使用包装器:
public class ConsumerOfPay { private IPay _pay; public ConsumerOfPay(IPay pay) { _pay = new PayWrapper(pay); } }
You could create a wrapper class that also implements IPay and have it capture the amount of time it took.
public class PayWrapper : IPay { private readonly IPay _wrapped; public PayWrapper(IPay wrapped) { if (wrapped == null) throw new ArgumentNullException(nameof(wrapped)); _wrapped = wrapped; } public void DecreasePay() { Stopwatch sw = new Stopwatch(); sw.Start(); _wrapped.DecreasePay(); sw.Stop(); Console.WriteLine(sw.Elapsed); } public void IncreasePay() { Stopwatch sw = new Stopwatch(); sw.Start(); _wrapped.IncreasePay(); sw.Stop(); Console.WriteLine(sw.Elapsed); } }
Then when a class gets an IPay, it can use the wrapper like this:
public class ConsumerOfPay { private IPay _pay; public ConsumerOfPay(IPay pay) { _pay = new PayWrapper(pay); } }
相关问答
更多-
TCP/IP模型是一个________。[2023-05-19]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
您可以创建一个也实现IPay的包装类,并让它捕获所花费的时间。 public class PayWrapper : IPay { private readonly IPay _wrapped; public PayWrapper(IPay wrapped) { if (wrapped == null) throw new ArgumentNullException(nameof(wrapped)); _wrapped = wrapped; } ...
-
IronPython将始终使用BindGetMember ,然后调用结果,因为这就是Python的工作方式 - 从对象中获取属性,然后调用它。 您的BindGetMember实现应该返回另一个实现BindInvokeMember动态对象,它将具有您需要的参数。 IronPython will always use BindGetMember and then Invoke the result because that's how Python works - get the attribute from ...
-
C#类和方法(C# classes and methods)[2023-07-19]
你在这里描述的基本上是活动记录模式或存储库模式之间的选择。 我建议您阅读这些模式并选择适合您的应用/体验/工具集的模式。 What you are describing here is basically a choice between the Active Record Pattern or the Repository Pattern. I'd advise you to read up on those patterns and choose whichever one fits your appl ... -
正如@GeorgeDuckett所说,T4模板可能是要走的路。 在我正在处理的应用程序中,我们使用它们很多,包括生成存储库,服务,ViewModel,枚举和最近的单元测试。 它们基本上是用VB或C#编写的代码生成脚本,查看XML文件的目录对于这些类型的模板都没有问题。 如果你确实选择了T4路线,那么有形T4编辑器绝对是必备的,它是免费下载的。 这是一个T4脚本的快速示例,该脚本应该或者非常接近您想要的: <#@ template language="C#" debug="true" hostspecific ...
-
C#非常动态的调用(C# very dynamic invocation)[2023-05-30]
我知道你写过你不喜欢反思,但这真的很难看吗? var result = x.GetType().GetMethod( "MethodName" ).Invoke( x, new object[] { methodParams }); 如果方法可能重载,则不能仅按名称去,而是需要知道要调用它的参数数量。 像这样的东西 var method = x.GetType() .GetMethods() .First(m => m.Name == "Method ... -
c#中方法的菜单(Menu for methods in c#)[2023-01-07]
您可以创建一个字典,其中练习编号为键,值为Action: class Program { static Dictionaryexercises = new Dictionary { // put the numbers with the exercise method here: {1, () => Exercise1()}, {2, () => Exercise2()}, }; ... -
C#:发现扩展方法(C#: Discovering Extension Methods)[2023-12-14]
如果您有源,则可以使用正则表达式搜索this Type identifier 。 考虑到它必须是函数的第一个参数这样的事实应该做的伎俩: \(this:b+:i:b+:i 至少通过这种方式,您可以发现扩展方法的定义位置并添加该命名空间,然后依赖智能感知。 只是在一个非平凡的项目中运行它,其中包含大量的扩展方法,并且它起到了很大的作用。 唯一的误报是这样的: if(this is Blah... 我们可以通过在搜索中添加static来修复,因为扩展方法必须是静态的: static.*\(this:b+:i ... -
将C ++ COM类转换为C#以供C ++可执行文件调用(Convert C++ COM class to C# for invocation by C++ executable)[2023-11-28]
由Hans Passant提供,答案是使用正确的[ComVisible],[Guid]和[InterfaceType]属性来装饰接口。 Courtesy of Hans Passant, the answer is to decorate the interfaces with the correct [ComVisible], [Guid] and [InterfaceType] attributes.