https://github.com/molnarmark/multex
🏗️ Flux Implementation done in Multi Theft Auto
https://github.com/molnarmark/multex
flux flux-application-architecture flux-architecture mta-server mtasa mtasa-lua multi-theft-auto
Last synced: about 2 months ago
JSON representation
🏗️ Flux Implementation done in Multi Theft Auto
- Host: GitHub
- URL: https://github.com/molnarmark/multex
- Owner: molnarmark
- Created: 2018-03-03T19:57:34.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-08T19:35:11.000Z (about 7 years ago)
- Last Synced: 2025-03-06T04:56:36.213Z (about 2 months ago)
- Topics: flux, flux-application-architecture, flux-architecture, mta-server, mtasa, mtasa-lua, multi-theft-auto
- Language: Lua
- Homepage:
- Size: 6.84 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Multex
[](https://github.com/ellerbrock/open-source-badge/)
[](https://github.com/ellerbrock/open-source-badge/)
[](http://makeapullrequest.com)## Introduction
Multex is an implementation of the `Flux` Architecture by [Facebook](http://facebook.com) for the [Multi Theft Auto](http://mtasa.com) modification.\
You can learn more about how `Flux` works [here](https://facebook.github.io/flux/).### Getting Started
Create a store by calling the exported createStore function:
```lua
local store = loadstring(createStore())()
```
You can set the initial state of a store by calling `setInitialState` on it:
```lua
store:setInitialState({counter = 0})
```### Events
You can also subscribe to various events that happen on the store main ones being:
- update
- computed_update### Computed Properties
Computed properties introduced in `Vuex` are also available in Multex.\
You can subscribe to a property change like so:
```lua
store:setComputedProperty("counter", function()
outputChatBox("Counter has changed. Let's do something.")
end)
```
### Hooks
Multex also offers you two very simple hooks you can use, those being `beforeAction` and `afterAction`.\
You can use them like so:
```lua
store:setHook("beforeAction", function()
outputChatBox("An action is about to take place.")
end)
```### Practical Example
Multex uses the traditional action handlers with a simple dispatch method.\
Here is a little practical example showing you the power of `Multex`.```lua
local store = loadstring(createStore())()
store:setInitialState({counter = 0})-- You can subscribe to the change of a property.
store:setComputedProperty("counter", function()
outputChatBox("Counter has changed.")
end)-- Let's handle some actions!
store:onAction(function(name, payload)
if name == "increment" then
outputChatBox("Increment action called with payload of " .. payload.value)
local state = store:getState()
store:setState({counter = state.counter + 1})
end
end)-- The update event is emitted whenever the state changes via setState()
store:on("update", function()
local counter = store:getState().counter
outputChatBox("State updated. Counter is now " .. counter)
end)-- Let's create some actions for our store
local actions = {
increment = function()
store:dispatch("increment", {value = 1})
end,
}actions.increment()
actions.increment()
actions.increment()
actions.increment()
actions.increment()
-- counter is now 5
```### Fancy buying me a beer?
If this project was helpful to you, you can buy me a beer if you feel like doing so. 🙂[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YM7E34E2LT4D8)