wicca v0.6.0
wicca
Requirements:
React Node.js backend
Use if you like these:
Stores Views Publishing Subscribing
Or if you desparately want to escape these:
Provider
components
REST
GraphQL
...but you should probably try this first:
Mobx
API
wicca/client
WiccaClient(clientParams) => wiccaClient
clientParams
clientParams.topics: string[]
An array of publishable and subscribable topics.
clientParams.onDisconnect?: function
Function in the form (reconnect) => { /* call reconnect(), or do something else. */ }
Automatically defined as (reconnect) => { reconnect() }
wiccaClient
wiccaClient.connect(url?: string)
Connect to Wicca server at URL.
URL automatically defined as window.location.host
.
wiccaClient.disconnect()
Disconnect from Wicca server.
wiccaClient.store(storeBase: object)
Store factory.
wiccaClient.view(viewClass: React.Component || () => React.Element)
View factory.
wiccaClient.publish.: function(message)
Publish function.
wiccaCLient.autorun(onRelevantStoreChange: function)
Runs function when store it reads from changes.
wicca/server
WiccaServer(serverParams) => wiccaServer
serverParams
serverParams.topics: string[]
Same as clientParams.topics.
serverParams.port: int
Port to run Wicca server on.
serverParams.server: http(s).Server
A server to run Wicca server on top of. (So you can slap Wicca on top of a pre-existing server with no changes(?))
serverParams.middleware({ token: string, topic: string, message?: JSON }, next: function)
Middleware used to define the third ctx
argument passed to message handlers. Use this to keep track of IAM stuff.
serverParams.onConnect(token: string)
Called when a client connects.
serverParams.onDisconnect(token: string)
Called when a client disconnects.
wiccaServer
wiccaServer.start()
Start the Wicca server.
wiccaServer.shutdown()
Shut down the Wicca server.
wiccaServer.publish.(message?: JSON, tokens: string[]) => disconnectedClients: string[] | null
Publish to clients identified by tokens. Returns array of tokens of clients that disconnected before successful dispatch.
wiccaServer.messageHandlers.: null | function(message?: JSON, reply: {topic: function}, ctx: any)
Server message handlers.
Set messageHandlers.<topic> = // your function
to assign a function to be called when a message is received from a client.
The reply
object allows you to reply directly to a message from a client via reply.<topic>(message)
.
Ctx is whatever your middleware passes to next()
, or { token }
by default.
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago