Support Events as actions #57
Comments
|
@seletz Just want to clarify first, with your example I'm thinking you were envisioning something like this? {
"$jason": {
"head": {
"actions": {
"$load": {
"type": "@JasonetteWebSocketPlugin.connect",
"options": {
"url": "wss://example.com/ws/echo"
}
},
"!WebSocket.message": {
"type": "$set",
"options": {
"messages": "{{var messages = $get.messages; messages.push($jason); return messages;}}"
},
"success": {
"type": "$render"
}
}
}
}
}
}I think it's best if we walk through using the new notification based action extension code 1. Add
|
|
Just realized this may work for some cases, but for cases like websockets I think we may need some sort of a "module holder" so that these daemons associated with the actions don't get garbage collected after execution.. Was this what you meant by registry? |
|
Please see PR #62 As for your comments -- I think I need more time to think them through. I'll follow up here. |
|
Was going to sit on this for a bit, but ran into the same architecture problem with the Android side I was working on tonight, so wrote the logic on Android first, and ported it back to iOS for discussion #63 It covers everything I mentioned above:
Further explanationBetter explained with an example. We want to do something like this: {
"$jason": {
"head": {
"actions": {
"$load": {
"type": "$util.alert",
"options": {
"title": "Enter username",
"description": "Enter username to join the chatroom",
"form": [{
"name": "username"
}]
},
"success": {
"type": "@websockets.connect",
"options": {
"url": "ws://chatroom.chatroom/chatroom",
"data": {
"username": "{{$jason.username}}"
}
}
}
},
"!websockets.message": {
"type": "$set",
"options": {
"messages": "{{ var buffer = $get.messages; buffer.push($jason); return buffer }}"
},
"success": {
"type": "$render"
}
},
"!websockets.connected": {
"type": "$util.banner",
"options": {
"title": "Connected",
"description": "Successfully connected to localhost"
}
}
}
}
}
}
First of all, for all this to work, the That's why I've added an NSMutableDictionary type Then when there's a new message from the websockets connection,
Then naturally it will kick off the action call chain. No need for additional logic. Basically Jason core functions as the action dispatch backbone. |
|
@gliechtenstein WRT the registry -- we could just do away with that by demanding that Event-enabled plug-ins must act as singletons. That way, nothing needs to be changed and plug-ins can stay very easy, on-demand things. What's not immediately clear to me is how a plug-in would react to events, i.e. how would plug-ins be able to register their own handlers? Im my original idea it would look something like this (beware, out-of-my head and not even syntax tested):
The above plug-in would be used like:
It's not clear to me how the above use case would work with your suggestion -- but maybe I'm missing something. |
As for the singleton idea,initially I wanted to tie it to the viewcontroller because that way they will automatically go away when the view closes. The reason I was thinking about it this way was because I was trying to make the websockets case work without making too much change to the existing architecture. Basically I was approaching this from a web browser metaphor, where any actions that were running gets reset when a user refreshes or moves away to another page. But upon thinking about your comment I think I can understand what you're saying. But just to clarify, do we need singletons (vs. tying them under viewcontrollers) because that will enable actions to exist across views? If so, can you give some examples? That would help us get on the same page. Regarding the "how would plug-ins be able to register their own handlers?" question:I feel like I am seriously misunderstanding your idea. I think it would help if you can provide full context to your example JSON:
More specifically, is this under Thanks! |
|
Actually, please ping me on slack when you see this, that would be better than going back and forth async |
seletz commentedNov 19, 2016
Motivation
So it looks like the plug-in approach #26 will use notifications to communicate with the core. This
opens new possibilities for integrations. For example, issue #49 is about web socket support. Such
a feature can live in a plug-in w/o problems.
However, web sockets are async in nature, that is, they can receive messages at any time. How
would users be able to react on those events?
Note: I use WebSocket as an example here. This is obviously useful for catching other
events and could replace the hard-coded "system events" in Jasonette.
Proposal
I propose a new action type for events. Those actions would "register" itself for a notification
handler by name:
Details
For the above to work, the hypothetical WebSocket plugin would send a notification on received messages with name
WebSocket.message.The
!WebSocket.messageaction would instruct the core to register a notification handler forthe
WebSocket.messagenotification and do a[[Jason client] success:notification.object]ifthe notification is received. This can be nicely done in a block.
All this could be done in a plug-in also. But this ia s feature which is core-worthy IMHO😄
Problems