L
L
l4m3r2019-05-01 15:49:53
Vue.js
l4m3r, 2019-05-01 15:49:53

Where to store business logic?

I started learning vue immediately from a combat example, and not from hello world: I decided to write a cellular automaton simulator (the game "Life", for example). I do not understand one architectural moment.
Let's say the screen is divided into 2 parts: the top settings toolbar and the rest of the area - in fact, the canvas of the game itself (webgl three-js).
As a result, we have 3 components:

<App>
   <Settings>
   <Grid>

1) It turns out that all the code and all the logic of the game should be in the Grid.vue file? Which will refer to Settings for parameters and actually render. Some kind of "divine object" turns out ... And somehow it is not included in the vue concept: after all, it is webgl, not dom.
2) I also thought to take out the logic separately from Vue. Create classes Cell.js, Game.js and more. Well then it turns out Grid is not strongly necessary.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dima Pautov, 2019-05-01
@l4m3r

Create classes Cell.js, Game.js
exactly. Vue does not prevent you from writing your own classes.
Create a folder, write your classes in it, then import them into templates and work.
It turns out that all the code and all the logic of the game should be in the Grid.vue file? Which will access Settings for parameters and actually render
- if you need to make the components communicate with each other, then it is best to use vuex, in which you change the values ​​from the Settings component, and Grid will look at these values ​​from vuex and do something. Thus, you will take out the project settings and be able to cling them from anywhere in the application, otherwise you will have noodles

E
E, 2019-05-01
@aylo

Read about vuex . And everything can be done through modules.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question