Skip to content

Commit bd8a1e6

Browse files
committed
Merge branch 'JediLuke-upgrade_guide_improvements_v0.11'
2 parents 2ccd105 + d4f0309 commit bd8a1e6

File tree

1 file changed

+128
-2
lines changed

1 file changed

+128
-2
lines changed

guides/upgrading_to_v0.11.md

Lines changed: 128 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Version v0.11 is a MAJOR overhaul from the top to the bottom. For the first time
66

77
This guide is a good first pass. As you use it in the Beta, if you see things that need improving, please contribute!
88

9-
9+
1010
* `Scenic.Cache` is gone. It is replaced by a **much** easier to use asset pipeline.
1111
* `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.
1212
* 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
6565

6666
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.
6767

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+
```
68138

69139
## Scene State
70140
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
75145

76146
This will require some porting work as you move to v0.11, but at least it feels like the right long-term solution.
77147

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:
165+
166+
```
167+
def handle_cast(msg, state) do
168+
new_graph = calc_new_graph(state)
169+
{:noreply, %{state|graph: new_graph}, push: new_graph}
170+
end
171+
```
172+
173+
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+
78192
```elixir
79193
defmodule MyDevice.Scene.Example do
80194
use Scenic.Scene
@@ -149,7 +263,7 @@ Here is an example from the Button control. In this case, update_color calls the
149263
def handle_input( {:cursor_button, {0, :press, _, _}}, :btn, scene ) do
150264
:ok = capture_input( scene, :cursor_button )
151265
152-
scene =
266+
scene =
153267
scene
154268
|> update_color( true, true )
155269
|> assign( pressed: true )
@@ -160,6 +274,18 @@ Here is an example from the Button control. In this case, update_color calls the
160274
161275
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.
162276
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}
286+
def validate(_), do: {:error, "Descriptive error message goes here."}
287+
```
288+
163289
164290
## [The Static Asset Library](overview_assets.html)
165291

0 commit comments

Comments
 (0)