vocksel / action-network Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Requiring the use of Rodux style actions for networking is proving to be more cumbersome than it's worth.
Initially I was hoping this would be a convenient and intuitive way to communicate between server/client, but it's pretty clunky. It's also confusing having actions that could either be used for networking, and for the game's state.
So I propose the following API:
network:on(string eventName)
Returns an RBXScriptSignal that can then be connected to for when this event occurs.
network:on("foo"):connect(function(arg1, arg2, ...) end)
network:fire(string eventName, ...)
Server: Fires the event to all clients with the given arguments.
Client: Fires the event to the server with the given arguments.
network:fireTo(Player/table playerOrPlayers, string eventName, ...)
Server only. Fires the event to the given player or array of players.
network:fireExceptTo(Player/table playerOrPlayers, string eventName, ...)
Server only. Fires the event to all players except the one(s) specified.
Standard networking example, similar to what people are used to with RemoteEvents:
-- client
local network = Network.new(remote)
network:init()
-- listen on the client for an event
network:on("foo"):connect(function(bar)
print(bar)
end)
-- server
local network = Network.new()
network:init()
-- fire the even, will print "bar" on the client
network:fireTo(game.Players.Player1, "foo", "bar")
Another example, which allows you to do something very similar to the native action dispatching currently in place:
-- someAction
local action = {
type = "action",
foo = true
}
return action
-- client
local network = Network.new(remote)
network:init()
network:on(someAction.type):connect(function(someAction)
print(action.foo) -- true
end)
-- server
local network = Network.new(remote)
network:init()
network:fire(someAction.type, action)
Right now there's no way to disconnect a listener. Take the Connection class from here and repurpose it for our Event class
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.