You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guides/upgrading_to_v0.11.md
+128-2Lines changed: 128 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ Version v0.11 is a MAJOR overhaul from the top to the bottom. For the first time
6
6
7
7
This guide is a good first pass. As you use it in the Beta, if you see things that need improving, please contribute!
8
8
9
-
9
+
10
10
*`Scenic.Cache` is gone. It is replaced by a **much** easier to use asset pipeline.
11
11
*`push_graph` is back. WHAT! Didn't it go away last time? Yes. I've been struggling with the way scene state is handled. Coupled with the scene state change (next in this list), it finally makes sense.
12
12
* State for a scene is now tracked similar to how you add state to a socket in a Phoenix Channel or a Plug conn. The state is always a `%Scene{}` object and you can assign() state into it.
@@ -64,6 +64,76 @@ Version 0.11 finally takes a crack at making Scenic remotable. Enough time and u
64
64
65
65
Now that the Kry10 Operating System is operational (Scenic long awaited design target), it was time to fix the things that didn't work so well and properly build remoting. These are the sorts of changes that have ripples up the stack and create breaking changes. So best to get it all done in fell swoop.
66
66
67
+
## Upgrading a v0.10 project to v0.11
68
+
69
+
* Update mix.exs
70
+
71
+
Delete your old scenic dependencies in `mix.exs`, they now look like this:
72
+
73
+
```
74
+
{:scenic, "~> 0.11.0-beta.0"},
75
+
{:scenic_driver_local, "~> 0.11.0-beta.0"},
76
+
```
77
+
78
+
You may need to use `mix deps.clean --all` and/or `mix deps.unlock` to get it to work.
79
+
80
+
* Change the incoming viewport options to be a keyword list
81
+
82
+
The main options for your Scenic app have changed from a map to a Keyword list. For example, if this was your old options map:
83
+
84
+
```
85
+
%{
86
+
name: :main_viewport,
87
+
size: {1200, 600},
88
+
default_scene: {MyProject.RootScene, nil},
89
+
drivers: [
90
+
%{
91
+
module: Scenic.Driver.Glfw,
92
+
name: :glfw,
93
+
opts: [resizeable: false, title: @title]
94
+
}
95
+
]
96
+
}
97
+
```
98
+
99
+
It would now look like this:
100
+
101
+
```
102
+
[
103
+
name: :main_viewport,
104
+
size: {1200, 600},
105
+
default_scene: {MyProject.RootScene, nil},
106
+
drivers: [
107
+
[
108
+
module: Scenic.Driver.Local,
109
+
name: :local
110
+
]
111
+
]
112
+
]
113
+
```
114
+
115
+
Finally, where you are adding Scenic to the supervision tree, you will probably have to wrap these options in another list, assuming you use the above config exactly as is:
116
+
117
+
```
118
+
children = [
119
+
{Scenic, [default_viewport_config()]},
120
+
]
121
+
```
122
+
123
+
where default_viewport_config() resolves to the above config list.
124
+
125
+
* Change the driver module
126
+
127
+
Assuming you have already upgraded your dependencies in mix.exs, you just need to make sure that you're using the correct driver module in your config.
128
+
129
+
```
130
+
drivers: [
131
+
[
132
+
module: Scenic.Driver.Local,
133
+
name: :local
134
+
]
135
+
]
136
+
```
67
137
68
138
## Scene State
69
139
The most immediate change that you will need to be addressed is now state in a scene is stored and how scenes are started up.
@@ -74,6 +144,50 @@ The only thing that really works is to adopt the same state model as sockets/con
74
144
75
145
This will require some porting work as you move to v0.11, but at least it feels like the right long-term solution.
76
146
147
+
### Upgrade steps
148
+
149
+
* Upgrade init/2 to init/3
150
+
151
+
Previously `init/2` accepted params, and a list of options. Now it also accepts a scene as the first parameter. This scene must be saved into the state, or set as the entire state of the scene. An example implementation is below.
152
+
153
+
```
154
+
@impl Scenic.Scene
155
+
def init(scene, _params, _opts) do
156
+
# put your init logic here
157
+
{:ok, scene}
158
+
end
159
+
```
160
+
161
+
* Update the scene to use push_graph/2
162
+
163
+
Previously in v0.10, graphs were pushed by including a `push: graph` option at the end of each callback:
This has now been deprecated, in favour of the function `push_graph/2`
173
+
174
+
Example:
175
+
176
+
```
177
+
def handle_cast(msg, scene) do
178
+
new_graph = calc_new_graph(scene, msg)
179
+
new_scene =
180
+
scene
181
+
|> assign(graph: new_graph)
182
+
|> push_graph(new_graph)
183
+
{:noreply, new_scene}
184
+
end
185
+
```
186
+
187
+
Note that, in this example, we are holding the `Scene` variable inside the state. This scene is passed in as the new param to `init/3` now, and we MUST use this scene when we perform a push_graph. We CANNOT simply construct a new scene and use that, it must be the orginal one.
188
+
189
+
### Example
190
+
77
191
```elixir
78
192
defmoduleMyDevice.Scene.Exampledo
79
193
useScenic.Scene
@@ -148,7 +262,7 @@ Here is an example from the Button control. In this case, update_color calls the
148
262
def handle_input( {:cursor_button, {0, :press, _, _}}, :btn, scene ) do
149
263
:ok = capture_input( scene, :cursor_button )
150
264
151
-
scene =
265
+
scene =
152
266
scene
153
267
|> update_color( true, true )
154
268
|> assign( pressed: true )
@@ -159,6 +273,18 @@ Here is an example from the Button control. In this case, update_color calls the
159
273
160
274
Also notice that which mouse button was clicked is now a number instead of :left or :right. it was presumptive to assume that :left was the primary button. This is neutral and no longer handedness-biased.
161
275
276
+
## Upgrading custom Scenic.Components
277
+
278
+
* Change verify/1 to validate/1
279
+
280
+
The name of the function which validates incoming parameters has changed, but the behaviour is essentially the same. An example implementation is below.
281
+
282
+
```
283
+
@impl Scenic.Component
284
+
def validate(data) when is_bitstring(data), do: {:ok, data}
0 commit comments