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.
@@ -65,6 +65,76 @@ Version 0.11 finally takes a crack at making Scenic remotable. Enough time and u
65
65
66
66
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.
67
67
68
+
## Upgrading a v0.10 project to v0.11
69
+
70
+
* Update mix.exs
71
+
72
+
Delete your old scenic dependencies in `mix.exs`, they now look like this:
73
+
74
+
```
75
+
{:scenic, "~> 0.11.0-beta.0"},
76
+
{:scenic_driver_local, "~> 0.11.0-beta.0"},
77
+
```
78
+
79
+
You may need to use `mix deps.clean --all` and/or `mix deps.unlock` to get it to work.
80
+
81
+
* Change the incoming viewport options to be a keyword list
82
+
83
+
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:
84
+
85
+
```
86
+
%{
87
+
name: :main_viewport,
88
+
size: {1200, 600},
89
+
default_scene: {MyProject.RootScene, nil},
90
+
drivers: [
91
+
%{
92
+
module: Scenic.Driver.Glfw,
93
+
name: :glfw,
94
+
opts: [resizeable: false, title: @title]
95
+
}
96
+
]
97
+
}
98
+
```
99
+
100
+
It would now look like this:
101
+
102
+
```
103
+
[
104
+
name: :main_viewport,
105
+
size: {1200, 600},
106
+
default_scene: {MyProject.RootScene, nil},
107
+
drivers: [
108
+
[
109
+
module: Scenic.Driver.Local,
110
+
name: :local
111
+
]
112
+
]
113
+
]
114
+
```
115
+
116
+
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:
117
+
118
+
```
119
+
children = [
120
+
{Scenic, [default_viewport_config()]},
121
+
]
122
+
```
123
+
124
+
where default_viewport_config() resolves to the above config list.
125
+
126
+
* Change the driver module
127
+
128
+
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.
129
+
130
+
```
131
+
drivers: [
132
+
[
133
+
module: Scenic.Driver.Local,
134
+
name: :local
135
+
]
136
+
]
137
+
```
68
138
69
139
## Scene State
70
140
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.
@@ -75,6 +145,50 @@ The only thing that really works is to adopt the same state model as sockets/con
75
145
76
146
This will require some porting work as you move to v0.11, but at least it feels like the right long-term solution.
77
147
148
+
### Upgrade steps
149
+
150
+
* Upgrade init/2 to init/3
151
+
152
+
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.
153
+
154
+
```
155
+
@impl Scenic.Scene
156
+
def init(scene, _params, _opts) do
157
+
# put your init logic here
158
+
{:ok, scene}
159
+
end
160
+
```
161
+
162
+
* Update the scene to use push_graph/2
163
+
164
+
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`
174
+
175
+
Example:
176
+
177
+
```
178
+
def handle_cast(msg, scene) do
179
+
new_graph = calc_new_graph(scene, msg)
180
+
new_scene =
181
+
scene
182
+
|> assign(graph: new_graph)
183
+
|> push_graph(new_graph)
184
+
{:noreply, new_scene}
185
+
end
186
+
```
187
+
188
+
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.
189
+
190
+
### Example
191
+
78
192
```elixir
79
193
defmoduleMyDevice.Scene.Exampledo
80
194
useScenic.Scene
@@ -149,7 +263,7 @@ Here is an example from the Button control. In this case, update_color calls the
149
263
def handle_input( {:cursor_button, {0, :press, _, _}}, :btn, scene ) do
150
264
:ok = capture_input( scene, :cursor_button )
151
265
152
-
scene =
266
+
scene =
153
267
scene
154
268
|> update_color( true, true )
155
269
|> assign( pressed: true )
@@ -160,6 +274,18 @@ Here is an example from the Button control. In this case, update_color calls the
160
274
161
275
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.
162
276
277
+
## Upgrading custom Scenic.Components
278
+
279
+
* Change verify/1 to validate/1
280
+
281
+
The name of the function which validates incoming parameters has changed, but the behaviour is essentially the same. An example implementation is below.
282
+
283
+
```
284
+
@impl Scenic.Component
285
+
def validate(data) when is_bitstring(data), do: {:ok, data}
0 commit comments