flok 0.0.63 → 0.0.64

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d369b592a35b8b2c078db3ac85240d1757cbe365
4
- data.tar.gz: bf82891bcedf8b23edafcea1a06dc4876043535c
3
+ metadata.gz: 23c9159d75fdda332b781181b9f67d2ac27ce050
4
+ data.tar.gz: c8708185f49d5971598bc07223b3dd826a74357c
5
5
  SHA512:
6
- metadata.gz: e58ba2e2620c41ee3e70960076766a63955219cd6fad8deebeaf5e067e10d38c053da078327b7b39a1e9d00a8b56af6e07858cacc60839bc7c9917f504a40eab
7
- data.tar.gz: 4ad97f13b5ed4da7a63dd15366d0507ece1cf43aa3379183e8ee1b48c707f0a61a59fe04552ccd94aba645b650d122600cfabedc62e86966196c86cd72515bef
6
+ metadata.gz: 89a25a47703e48edb20ec062af27290f28cd4029fa15ebc48b2faaf4a01a8c5559f5db93d525191d77c1491954e9d1edfe813a14e654dd8447df77992b25ba18
7
+ data.tar.gz: 4af82d9ce8f48639b99e4b710b5771da4129c3bd792b6b7a67bf0966ac4bf994456ab4eefaed0b2e1c84ff17309fc55e101b7564fc4586d5fae74dcd2d4b67b9
@@ -78,7 +78,8 @@ function _embed(vc_name, sp, context, event_gw) {
78
78
  action: "choose_action",
79
79
  cte: cte,
80
80
  embeds: embeds,
81
- event_gw: event_gw
81
+ event_gw: event_gw,
82
+ stack: [],
82
83
  };
83
84
 
84
85
  //Register controller base with the struct, we already requested base
data/docs/client_api.md CHANGED
@@ -5,6 +5,7 @@ Client API covers controller action event handlers.
5
5
  * Embed(view_controller_name, spot_name, context) - Embed a view controller with the name `view_controller_name` inside the current view controller at the spot with a context
6
6
  * Goto(action_name) - Change actions
7
7
  * Push(action_name) - This works just like `Goto` except that `Pop` will restore the last action
8
+ * Pop(action_name) - This is to be used after `Push` and will restore the state previous to the `Push`.
8
9
  * Request(service_insatnce_name, ename, params) Initiate a service. See [Services](./services.md) for more info.
9
10
  * Send(event_name, info) - Send a custom event on the main queue.
10
11
  * Raise(event_name, info) - Will send an event to the parent view controller (and it will bubble up, following `event_gw` which is set in `Embed` as the parent controller
data/docs/datatypes.md CHANGED
@@ -43,5 +43,7 @@ controller_info {
43
43
  action: //The name of the current action that is active
44
44
  cte: //The ctable entry pertaining to this controller
45
45
  embeds: //An array of arrays, where position 0 is the spot after `main`, each element in the array is a view controller base pointer.
46
+ stack: [{action:, embeds:}] //When pushing, the stack contains a copy of the controller_info's action's and a reference to the embeds from the previous layer.
47
+ event_gw: //When an event cannot be serviced, it is given to the gateway to continue propogating
46
48
  }
47
49
  ```
@@ -219,7 +219,11 @@ module Flok
219
219
 
220
220
  #Switch the actions, reset embeds, and call on_entry
221
221
  res = %{
222
+ //Save state
222
223
  var old_action = __info__.action;
224
+ var old_embeds = __info__.embeds;
225
+ __info__.stack.push({action: old_action, embeds: old_embeds});
226
+
223
227
  __info__.action = "#{action_name}";
224
228
 
225
229
  //Prep embeds array, embeds[0] refers to the spot bp+2 (bp is vc, bp+1 is main)
@@ -232,11 +236,6 @@ module Flok
232
236
  //located in ctable
233
237
  __info__.cte.actions[__info__.action].on_entry(__base__)
234
238
 
235
- //'choose_action' pseudo-action will be sent as 'null' as it's the initial state
236
- if (old_action === "choose_action") {
237
- old_action = null;
238
- }
239
-
240
239
  //Send off event for action change
241
240
  main_q.push([3, "if_event", __base__, "action", {
242
241
  from: old_action,
@@ -250,8 +249,38 @@ module Flok
250
249
  l.gsub! /\)$/, ""
251
250
  l.gsub! /\);$/, ""
252
251
  o = l.split(",").map{|e| e.strip}
252
+ #Switch the actions, reset embeds, and call on_entry
253
+ res = %{
254
+ var restore_info = __info__.stack.pop();
255
+
256
+ //Retrieve the original action info
257
+ var orig_action = restore_info.action;
258
+ var orig_embeds = restore_info.embeds;
259
+
260
+ //Save the old action
261
+ //var old_action = __info__.action;
262
+
263
+ //Restore the action we pushed from
264
+ __info__.action = orig_action;
253
265
 
254
- #out.puts res
266
+ //Remove all views, we don't have to recurse because removal of a view
267
+ //is supposed to remove *all* view controllers of that tree as well.
268
+ var embeds = __info__.embeds;
269
+ for (var i = 0; i < __info__.embeds.length; ++i) {
270
+ for (var j = 0; j < __info__.embeds[i].length; ++j) {
271
+ //Free +1 because that will be the 'main' view
272
+ main_q.push([1, "if_free_view", embeds[i][j]+1]);
273
+
274
+ //Call dealloc on the controller
275
+ tel_deref(embeds[i][j]).cte.__dealloc__(embeds[i][j]);
276
+ }
277
+ }
278
+
279
+ //Restore embeds
280
+ __info__.embeds = orig_embeds;
281
+ }
282
+
283
+ out.puts res
255
284
  #Request(service_instance_name, ename, info)
256
285
  elsif l =~ /Request/
257
286
  l.strip!
data/lib/flok/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Flok
2
- VERSION = "0.0.63"
2
+ VERSION = "0.0.64"
3
3
  end
data/spec/env/kern.rb CHANGED
@@ -195,6 +195,7 @@ shared_context "kern" do
195
195
  #Expect the queue to not contain a message matching
196
196
  def expect_not_to_contain msg_name, &block
197
197
  original_q = JSON.parse(@q.to_json)
198
+ @cq = []
198
199
 
199
200
  loop do
200
201
  if @q.count == 0 and @cq.count == 0
@@ -1,9 +1,14 @@
1
1
  controller :my_controller do
2
2
  spots "hello", "world"
3
3
 
4
+ on_entry %{
5
+ my_action_entered_count = 0;
6
+ }
7
+
4
8
  action :my_action do
5
9
  on_entry %{
6
10
  Embed("my_controller2", "hello", {});
11
+ my_action_entered_count += 1;
7
12
  }
8
13
 
9
14
  on "test_event", %{
@@ -13,6 +18,7 @@ controller :my_controller do
13
18
 
14
19
  action :my_other_action do
15
20
  on_entry %{
21
+ Embed("my_controller3", "hello", {});
16
22
  my_other_action_on_entry_called = true;
17
23
  }
18
24
 
@@ -28,3 +34,12 @@ controller :my_controller2 do
28
34
  }
29
35
  end
30
36
  end
37
+
38
+ controller :my_controller3 do
39
+ action :my_action do
40
+ on_entry %{
41
+ my_controller3_main_view_bp = __base__+1;
42
+ }
43
+ end
44
+ end
45
+
@@ -127,12 +127,14 @@ RSpec.describe "kern:controller_spec" do
127
127
  action = info.action
128
128
  cte = info.cte
129
129
  event_gw = info.event_gw
130
+ stack = info.stack
130
131
  }
131
132
 
132
133
  expect(ctx.eval('context')).not_to eq(nil)
133
134
  expect(ctx.eval('action')).not_to eq(nil)
134
135
  expect(ctx.eval('cte')).not_to eq(nil)
135
136
  expect(ctx.eval('"event_gw" in info')).not_to eq(nil)
137
+ expect(ctx.eval('stack')).not_to eq(nil)
136
138
  end
137
139
 
138
140
  it "calls on_entry with the base pointer when a controller is embedded for the initial action" do
@@ -351,19 +353,52 @@ RSpec.describe "kern:controller_spec" do
351
353
  ctx = flok_new_user File.read('./spec/kern/assets/push_pop.rb')
352
354
 
353
355
  #Run the embed function
354
- ctx.eval %{
356
+ dump = ctx.evald %{
355
357
  //Call embed on main root view
356
- base = _embed("my_controller", 0, {}, null);
358
+ dump["base"] = _embed("my_controller", 0, {}, null);
357
359
 
358
- //Drain queue with test event
359
- int_dispatch([3, "int_event", base, "test_event", {}]);
360
+ //The controller's info
361
+ dump["controller_info"] = tel_deref(dump["base"]);
362
+ dump["ctable_entry"] = dump["controller_info"]["cte"];
363
+
364
+ //Dump the embeds array before we switch anything around, this is the embeds for `my_action`
365
+ dump["my_action_embeds_original_array"] = JSON.parse(JSON.stringify(dump["controller_info"]["embeds"]));
366
+
367
+ //Push the controller to 'my_other_action'
368
+ int_dispatch([3, "int_event", dump["base"], "test_event", {}]);
369
+
370
+ //Pop the controller back to 'my_action'
371
+ int_dispatch([3, "int_event", dump["base"], "back", {}]);
372
+
373
+ //The second action was entered
374
+ dump["my_other_action_on_entry_called"] = my_other_action_on_entry_called;
375
+
376
+ //The first action was not entered twice
377
+ dump["my_action_entered_count"] = my_action_entered_count;
378
+
379
+ //The poped controller's base pointer for the main view
380
+ dump["my_controller3_main_view_bp"] = my_controller3_main_view_bp;
360
381
  }
361
382
 
362
- #Now we expect the action for the controller to be 'my_other_action' and for it's on_entry
363
- #to be called
364
- expect(ctx.eval("my_other_action_on_entry_called")).not_to eq(nil)
365
- end
383
+ #The controller's instance info `action` field was changed back to the old action
384
+ expect(dump["controller_info"]["action"]).to eq("my_action")
366
385
 
386
+ #The controller's embeds is now restored back to the original embeds from 'my_action'
387
+ expect(dump["controller_info"]["embeds"]).to eq(dump["my_action_embeds_original_array"])
388
+
389
+ #Does dealloc the pushed controller, we can check to see if the view was destroyed
390
+ @driver.ignore_up_to "if_free_view"
391
+ @driver.mexpect("if_free_view", [dump["my_controller3_main_view_bp"]])
392
+
393
+ #Do not get a notification for any more removals, or creations
394
+ @driver.expect_not_to_contain "if_free_view"
395
+ @driver.expect_not_to_contain "if_init_view"
396
+
397
+ #Do not get a notification for the view hierarchy about the change
398
+ @driver.expect_not_to_contain "if_event" do |e|
399
+ next e[2] == {"from" => "my_other_action", "to" => "my_action"}
400
+ end
401
+ end
367
402
 
368
403
  it "Does tear down the old embedded view from the embedded view controller when switching actions" do
369
404
  #Compile the controller
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flok
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.63
4
+ version: 0.0.64
5
5
  platform: ruby
6
6
  authors:
7
7
  - seo