flok 0.0.62 → 0.0.63
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/docs/client_api.md +1 -0
- data/docs/datatypes.md +1 -1
- data/lib/flok/user_compiler.rb +44 -0
- data/lib/flok/version.rb +1 -1
- data/spec/env/kern.rb +40 -0
- data/spec/etc/user_compiler_spec.rb +1 -0
- data/spec/kern/assets/push.rb +26 -0
- data/spec/kern/assets/push_pop.rb +30 -0
- data/spec/kern/controller_spec.rb +62 -2
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d369b592a35b8b2c078db3ac85240d1757cbe365
|
4
|
+
data.tar.gz: bf82891bcedf8b23edafcea1a06dc4876043535c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e58ba2e2620c41ee3e70960076766a63955219cd6fad8deebeaf5e067e10d38c053da078327b7b39a1e9d00a8b56af6e07858cacc60839bc7c9917f504a40eab
|
7
|
+
data.tar.gz: 4ad97f13b5ed4da7a63dd15366d0507ece1cf43aa3379183e8ee1b48c707f0a61a59fe04552ccd94aba645b650d122600cfabedc62e86966196c86cd72515bef
|
data/docs/client_api.md
CHANGED
@@ -4,6 +4,7 @@ Client API covers controller action event handlers.
|
|
4
4
|
### Controller MACROS
|
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
|
+
* Push(action_name) - This works just like `Goto` except that `Pop` will restore the last action
|
7
8
|
* Request(service_insatnce_name, ename, params) Initiate a service. See [Services](./services.md) for more info.
|
8
9
|
* Send(event_name, info) - Send a custom event on the main queue.
|
9
10
|
* 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
@@ -10,7 +10,7 @@ be looked up as `ctable[controller_name]`.
|
|
10
10
|
ctable_entry {
|
11
11
|
root_view, //A constant string of the name of the view this controller sets as it's root view.
|
12
12
|
actions, //A dictionary [String:action_info] that corresponds to a dictionary of action_info object's based on the action's name.
|
13
|
-
spots, //An array fo spot names for this controller
|
13
|
+
spots, //An array fo spot names for this controller, by default, the 'main' spot is counted as 1 spot.
|
14
14
|
name, //The name of the controller, useful for certain lookup operations, this is also the ctable key
|
15
15
|
__init__, //A function that is called when this controller is created. Signals service connection and the controller on_entry bits.
|
16
16
|
Additionally, all interval timers are configured here based on their unique names. Actions that are not active will not receive these events (they
|
data/lib/flok/user_compiler.rb
CHANGED
@@ -208,6 +208,50 @@ module Flok
|
|
208
208
|
}]);
|
209
209
|
}
|
210
210
|
out.puts res
|
211
|
+
elsif l =~ /Push/
|
212
|
+
l.strip!
|
213
|
+
l.gsub!(/Push\(/, "")
|
214
|
+
l.gsub! /\)$/, ""
|
215
|
+
l.gsub! /\);$/, ""
|
216
|
+
o = l.split(",").map{|e| e.strip}
|
217
|
+
|
218
|
+
action_name = o.shift.gsub(/"/, "")
|
219
|
+
|
220
|
+
#Switch the actions, reset embeds, and call on_entry
|
221
|
+
res = %{
|
222
|
+
var old_action = __info__.action;
|
223
|
+
__info__.action = "#{action_name}";
|
224
|
+
|
225
|
+
//Prep embeds array, embeds[0] refers to the spot bp+2 (bp is vc, bp+1 is main)
|
226
|
+
__info__.embeds = [];
|
227
|
+
for (var i = 1; i < #{@controller.spots.count}; ++i) {
|
228
|
+
__info__.embeds.push([]);
|
229
|
+
}
|
230
|
+
|
231
|
+
//Call on_entry for the new action via the singleton on_entry
|
232
|
+
//located in ctable
|
233
|
+
__info__.cte.actions[__info__.action].on_entry(__base__)
|
234
|
+
|
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
|
+
//Send off event for action change
|
241
|
+
main_q.push([3, "if_event", __base__, "action", {
|
242
|
+
from: old_action,
|
243
|
+
to: "#{action_name}"
|
244
|
+
}]);
|
245
|
+
}
|
246
|
+
out.puts res
|
247
|
+
elsif l =~ /Pop/
|
248
|
+
l.strip!
|
249
|
+
l.gsub!(/Pop\(/, "")
|
250
|
+
l.gsub! /\)$/, ""
|
251
|
+
l.gsub! /\);$/, ""
|
252
|
+
o = l.split(",").map{|e| e.strip}
|
253
|
+
|
254
|
+
#out.puts res
|
211
255
|
#Request(service_instance_name, ename, info)
|
212
256
|
elsif l =~ /Request/
|
213
257
|
l.strip!
|
data/lib/flok/version.rb
CHANGED
data/spec/env/kern.rb
CHANGED
@@ -192,6 +192,46 @@ shared_context "kern" do
|
|
192
192
|
end
|
193
193
|
end
|
194
194
|
|
195
|
+
#Expect the queue to not contain a message matching
|
196
|
+
def expect_not_to_contain msg_name, &block
|
197
|
+
original_q = JSON.parse(@q.to_json)
|
198
|
+
|
199
|
+
loop do
|
200
|
+
if @q.count == 0 and @cq.count == 0
|
201
|
+
#Good
|
202
|
+
@q = original_q
|
203
|
+
@cq = nil
|
204
|
+
return
|
205
|
+
end
|
206
|
+
#Dequeue from multi-priority queue if possible
|
207
|
+
if @cq.nil? or @cq.count == 0
|
208
|
+
@cq = @q.shift
|
209
|
+
@cp = @cq.shift #save priority
|
210
|
+
end
|
211
|
+
|
212
|
+
#Check to see if it's the correct item
|
213
|
+
arg_len = @cq.shift
|
214
|
+
name = @cq.shift
|
215
|
+
if arg_len.class == String
|
216
|
+
$stderr.puts "Arg len is: #{arg_len.inspect}"
|
217
|
+
$stderr.puts "Name is #{name.inspect}"
|
218
|
+
end
|
219
|
+
args = @cq.shift(arg_len)
|
220
|
+
|
221
|
+
#Matches message name
|
222
|
+
if name == msg_name
|
223
|
+
#Optional test block
|
224
|
+
if block
|
225
|
+
next unless block.call(args)
|
226
|
+
end
|
227
|
+
|
228
|
+
#Uh oh, we found one!
|
229
|
+
block_info = block ? " You gave a block to filter... check the code to see what it's checking for, it's more than just the message name" : ""
|
230
|
+
raise "Expected not to find a message matching #{msg_name.inspect} in the queue, but found one!#{block_info}"
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
195
235
|
#Retrieve a message, we at least expect a name and priority
|
196
236
|
def get msg_name, priority=0
|
197
237
|
#Dequeue from multi-priority queue if possible
|
@@ -0,0 +1,26 @@
|
|
1
|
+
controller :my_controller do
|
2
|
+
spots "hello", "world"
|
3
|
+
|
4
|
+
action :my_action do
|
5
|
+
on_entry %{
|
6
|
+
Embed("my_controller2", "hello", {});
|
7
|
+
}
|
8
|
+
|
9
|
+
on "test_event", %{
|
10
|
+
Push("my_other_action")
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
action :my_other_action do
|
15
|
+
on_entry %{
|
16
|
+
my_other_action_on_entry_called = true;
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
controller :my_controller2 do
|
22
|
+
action :my_action do
|
23
|
+
on_entry %{
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
controller :my_controller do
|
2
|
+
spots "hello", "world"
|
3
|
+
|
4
|
+
action :my_action do
|
5
|
+
on_entry %{
|
6
|
+
Embed("my_controller2", "hello", {});
|
7
|
+
}
|
8
|
+
|
9
|
+
on "test_event", %{
|
10
|
+
Push("my_other_action")
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
action :my_other_action do
|
15
|
+
on_entry %{
|
16
|
+
my_other_action_on_entry_called = true;
|
17
|
+
}
|
18
|
+
|
19
|
+
on "back", %{
|
20
|
+
Pop();
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
controller :my_controller2 do
|
26
|
+
action :my_action do
|
27
|
+
on_entry %{
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
@@ -75,7 +75,7 @@ RSpec.describe "kern:controller_spec" do
|
|
75
75
|
end
|
76
76
|
|
77
77
|
#Can initialize a controller via embed and the sub-controller has the correct info
|
78
|
-
it "Can initiate a controller via _embed" do
|
78
|
+
it "Can initiate a controller with a sub-controller via _embed" do
|
79
79
|
#Compile the controller
|
80
80
|
ctx = flok_new_user File.read('./spec/kern/assets/embed_info.rb')
|
81
81
|
|
@@ -287,7 +287,7 @@ RSpec.describe "kern:controller_spec" do
|
|
287
287
|
expect(embeds).to eq([[base+4], []])
|
288
288
|
end
|
289
289
|
|
290
|
-
it "Can receive 'test_event' and change actions" do
|
290
|
+
it "Can receive 'test_event' and change actions via Goto" do
|
291
291
|
#Compile the controller
|
292
292
|
ctx = flok_new_user File.read('./spec/kern/assets/goto.rb')
|
293
293
|
|
@@ -305,6 +305,66 @@ RSpec.describe "kern:controller_spec" do
|
|
305
305
|
expect(ctx.eval("my_other_action_on_entry_called")).not_to eq(nil)
|
306
306
|
end
|
307
307
|
|
308
|
+
it "Can receive 'test_event' and change actions via Push" do
|
309
|
+
#Compile the controller
|
310
|
+
ctx = flok_new_user File.read('./spec/kern/assets/push.rb')
|
311
|
+
|
312
|
+
#Run the embed function
|
313
|
+
dump = ctx.evald %{
|
314
|
+
//Call embed on main root view
|
315
|
+
base = _embed("my_controller", 0, {}, null);
|
316
|
+
|
317
|
+
//Drain queue with test event
|
318
|
+
int_dispatch([3, "int_event", base, "test_event", {}]);
|
319
|
+
|
320
|
+
//The second action was entered
|
321
|
+
dump["my_other_action_on_entry_called"] = my_other_action_on_entry_called;
|
322
|
+
|
323
|
+
//The controller's info
|
324
|
+
dump["controller_info"] = tel_deref(base);
|
325
|
+
dump["ctable_entry"] = dump["controller_info"]["cte"];
|
326
|
+
}
|
327
|
+
|
328
|
+
#The controller's instance info `action` field was changed to the new action
|
329
|
+
expect(dump["controller_info"]["action"]).to eq("my_other_action")
|
330
|
+
|
331
|
+
#The controller's instance embeds array is the correct blank version
|
332
|
+
#Each blank array in embeds refers to one spot (not including the main spot)
|
333
|
+
spot_count = dump["ctable_entry"]["spots"].count-1
|
334
|
+
expect(dump["controller_info"]["embeds"]).to eq((1..spot_count).map{|e| []})
|
335
|
+
|
336
|
+
#Does not dealloc the controller (and kill views)
|
337
|
+
@driver.expect_not_to_contain "if_free_view"
|
338
|
+
|
339
|
+
#Controller's action was called
|
340
|
+
expect(dump["my_other_action_on_entry_called"]).to eq(true)
|
341
|
+
|
342
|
+
#Got a notification for the view hierarchy about the change
|
343
|
+
@driver.ignore_up_to "if_event" do |e|
|
344
|
+
next e[2] == {"from" => "my_action", "to" => "my_other_action"}
|
345
|
+
end
|
346
|
+
@driver.mexpect("if_event", [Integer, "action", {"from" => "my_action", "to" => "my_other_action"}])
|
347
|
+
end
|
348
|
+
|
349
|
+
it "Can receive 'test_event' and change actions via Push and then back with Pop" do
|
350
|
+
#Compile the controller
|
351
|
+
ctx = flok_new_user File.read('./spec/kern/assets/push_pop.rb')
|
352
|
+
|
353
|
+
#Run the embed function
|
354
|
+
ctx.eval %{
|
355
|
+
//Call embed on main root view
|
356
|
+
base = _embed("my_controller", 0, {}, null);
|
357
|
+
|
358
|
+
//Drain queue with test event
|
359
|
+
int_dispatch([3, "int_event", base, "test_event", {}]);
|
360
|
+
}
|
361
|
+
|
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
|
366
|
+
|
367
|
+
|
308
368
|
it "Does tear down the old embedded view from the embedded view controller when switching actions" do
|
309
369
|
#Compile the controller
|
310
370
|
ctx = flok_new_user File.read('./spec/kern/assets/goto.rb')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flok
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.63
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- seo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: execjs
|
@@ -1159,6 +1159,8 @@ files:
|
|
1159
1159
|
- spec/kern/assets/interval3.rb
|
1160
1160
|
- spec/kern/assets/lower_event.rb
|
1161
1161
|
- spec/kern/assets/no_choose_action.rb
|
1162
|
+
- spec/kern/assets/push.rb
|
1163
|
+
- spec/kern/assets/push_pop.rb
|
1162
1164
|
- spec/kern/assets/raise_event.rb
|
1163
1165
|
- spec/kern/assets/rest_service/config0.rb
|
1164
1166
|
- spec/kern/assets/rest_service/controller0.rb
|
@@ -2086,6 +2088,8 @@ test_files:
|
|
2086
2088
|
- spec/kern/assets/interval3.rb
|
2087
2089
|
- spec/kern/assets/lower_event.rb
|
2088
2090
|
- spec/kern/assets/no_choose_action.rb
|
2091
|
+
- spec/kern/assets/push.rb
|
2092
|
+
- spec/kern/assets/push_pop.rb
|
2089
2093
|
- spec/kern/assets/raise_event.rb
|
2090
2094
|
- spec/kern/assets/rest_service/config0.rb
|
2091
2095
|
- spec/kern/assets/rest_service/controller0.rb
|