@yuneta/gobj-js 7.6.6 → 7.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -386,6 +386,13 @@ var Event_Type = class {
386
386
  function tab() {
387
387
  return " ".repeat(Math.max(0, __inside__ * 2 - 1));
388
388
  }
389
+ var __trace_machine_format__ = 0;
390
+ function gobj_set_trace_machine_format(format) {
391
+ __trace_machine_format__ = Number(format) === 1 ? 1 : 0;
392
+ }
393
+ function gobj_trace_machine_format() {
394
+ return __trace_machine_format__;
395
+ }
389
396
  /************************************************************
390
397
  *
391
398
  ************************************************************/
@@ -2118,9 +2125,12 @@ function gobj_send_event(dst, event, kw, src) {
2118
2125
  return -1;
2119
2126
  }
2120
2127
  if (tracea) {
2121
- let action_name = "";
2122
- if (event_action.action) action_name = get_function_name(event_action.action);
2123
- trace_machine(sprintf("🔄 mach(%s%s^%s), st: %s, ev: %s%s%s, ac: %s, from(%s%s^%s)", !dst.running ? "!!" : "", gobj_gclass_name(dst), gobj_name(dst), state.state_name, "", event ? event : "", "", action_name, src && !src.running ? "!!" : "", gobj_gclass_name(src), gobj_name(src)));
2128
+ if (__trace_machine_format__ === 1) trace_machine(sprintf("🔄 %s %s%s %s from %s%s", event ? event : "", !dst.running ? "!!" : "", gobj_short_name(dst), state.state_name, src && !src.running ? "!!" : "", gobj_short_name(src)));
2129
+ else {
2130
+ let action_name = "";
2131
+ if (event_action.action) action_name = get_function_name(event_action.action);
2132
+ trace_machine(sprintf("🔄 mach(%s%s^%s), st: %s, ev: %s%s%s, ac: %s, from(%s%s^%s)", !dst.running ? "!!" : "", gobj_gclass_name(dst), gobj_name(dst), state.state_name, "", event ? event : "", "", action_name, src && !src.running ? "!!" : "", gobj_gclass_name(src), gobj_name(src)));
2133
+ }
2124
2134
  if (kw) {
2125
2135
  if (tracea > 1) {
2126
2136
  if (json_object_size(kw)) trace_json(kw);
@@ -2132,7 +2142,7 @@ function gobj_send_event(dst, event, kw, src) {
2132
2142
  try {
2133
2143
  if (event_action.action) ret = event_action.action(dst, event, kw, src);
2134
2144
  } finally {}
2135
- if (tracea && !(dst.obflag & obflag_t.obflag_destroyed)) trace_machine(sprintf("<- mach(%s%s^%s), st: %s, ev: %s, ret: %d", !dst.running ? "!!" : "", gobj_gclass_name(dst), gobj_name(dst), dst.current_state.state_name, event ? event : "", is_number(ret) ? ret : 0));
2145
+ if (tracea && __trace_machine_format__ !== 1 && !(dst.obflag & obflag_t.obflag_destroyed)) trace_machine(sprintf("<- mach(%s%s^%s), st: %s, ev: %s, ret: %d", !dst.running ? "!!" : "", gobj_gclass_name(dst), gobj_name(dst), dst.current_state.state_name, event ? event : "", is_number(ret) ? ret : 0));
2136
2146
  __inside__--;
2137
2147
  return ret;
2138
2148
  }
@@ -2616,6 +2626,15 @@ var f_error = _console.error;
2616
2626
  var f_warning = _console.warn;
2617
2627
  var f_info = _console.info;
2618
2628
  var f_debug = _console.debug;
2629
+ var __log_callback__ = null;
2630
+ function set_log_callback(fn) {
2631
+ __log_callback__ = typeof fn === "function" ? fn : null;
2632
+ }
2633
+ function emit_log_callback(level, msg, hora) {
2634
+ if (__log_callback__) try {
2635
+ __log_callback__(level, msg, hora);
2636
+ } catch (e) {}
2637
+ }
2619
2638
  function set_remote_log_functions(remote_log_fn) {
2620
2639
  if (remote_log_fn) {
2621
2640
  f_error = remote_log_fn;
@@ -2655,6 +2674,7 @@ function log_error(format) {
2655
2674
  window.console.error("%c" + hora + " ERROR: " + String(msg), "color:red");
2656
2675
  f_error(`${hora} ERROR: ${String(msg)}`);
2657
2676
  }
2677
+ emit_log_callback("error", msg, hora);
2658
2678
  }
2659
2679
  function log_warning(format) {
2660
2680
  let msg = format_log(format);
@@ -2664,25 +2684,30 @@ function log_warning(format) {
2664
2684
  window.console.warn("%c" + hora + " WARNING: " + String(msg), "color:yellow");
2665
2685
  f_warning(`${hora} WARNING: ${String(msg)}`);
2666
2686
  }
2687
+ emit_log_callback("warning", msg, hora);
2667
2688
  }
2668
2689
  function log_info(format) {
2669
2690
  let msg = format_log(format);
2670
2691
  let hora = current_timestamp();
2671
2692
  if (f_info) f_info("%c" + hora + " INFO: " + String(msg), "color:cyan");
2693
+ emit_log_callback("info", msg, hora);
2672
2694
  }
2673
2695
  function log_debug(format) {
2674
2696
  let msg = format_log(format);
2675
2697
  let hora = current_timestamp();
2676
2698
  if (f_debug) f_debug("%c" + hora + " DEBUG: " + String(msg), "color:silver");
2699
+ emit_log_callback("debug", msg, hora);
2677
2700
  }
2678
2701
  function trace_msg(format) {
2679
2702
  let msg = format_log(format);
2680
2703
  let hora = current_timestamp();
2681
2704
  if (f_debug) f_debug("%c" + hora + " MSG: " + String(msg), "color:cyan");
2705
+ emit_log_callback("msg", msg, hora);
2682
2706
  }
2683
2707
  function trace_json(jn, msg) {
2684
2708
  if (msg) window.console.warn("=====> " + msg);
2685
2709
  window.console.dir(jn);
2710
+ emit_log_callback("json", jn, current_timestamp());
2686
2711
  }
2687
2712
  /************************************************************
2688
2713
  * Duplicate an object (new references)
@@ -5481,13 +5506,7 @@ function mt_stop(gobj) {
5481
5506
  let priv = gobj.priv;
5482
5507
  clear_timeout(priv.gobj_timer);
5483
5508
  gobj_stop(priv.gobj_timer);
5484
- if (priv.websocket) {
5485
- priv.websocket.onopen = null;
5486
- priv.websocket.onmessage = null;
5487
- priv.websocket.onerror = null;
5488
- priv.websocket.onclose = null;
5489
- close_websocket(gobj);
5490
- }
5509
+ if (priv.websocket) close_websocket(gobj);
5491
5510
  return 0;
5492
5511
  }
5493
5512
  /***************************************************************
@@ -5621,6 +5640,7 @@ function setup_websocket(gobj) {
5621
5640
  }, gobj);
5622
5641
  };
5623
5642
  websocket.onclose = (e) => {
5643
+ if (gobj_is_destroying(gobj)) return;
5624
5644
  if (!gobj_read_bool_attr(gobj_yuno(), "browser_beforeunload")) gobj_send_event(gobj, "EV_ON_CLOSE", {
5625
5645
  url,
5626
5646
  e
@@ -6229,6 +6249,7 @@ exports.gobj_search_path = gobj_search_path;
6229
6249
  exports.gobj_send_event = gobj_send_event;
6230
6250
  exports.gobj_services = gobj_services;
6231
6251
  exports.gobj_set_bottom_gobj = gobj_set_bottom_gobj;
6252
+ exports.gobj_set_trace_machine_format = gobj_set_trace_machine_format;
6232
6253
  exports.gobj_short_name = gobj_short_name;
6233
6254
  exports.gobj_start = gobj_start;
6234
6255
  exports.gobj_start_children = gobj_start_children;
@@ -6239,6 +6260,7 @@ exports.gobj_stop = gobj_stop;
6239
6260
  exports.gobj_stop_children = gobj_stop_children;
6240
6261
  exports.gobj_stop_tree = gobj_stop_tree;
6241
6262
  exports.gobj_subscribe_event = gobj_subscribe_event;
6263
+ exports.gobj_trace_machine_format = gobj_trace_machine_format;
6242
6264
  exports.gobj_unsubscribe_event = gobj_unsubscribe_event;
6243
6265
  exports.gobj_unsubscribe_list = gobj_unsubscribe_list;
6244
6266
  exports.gobj_walk_gobj_children = gobj_walk_gobj_children;
@@ -6341,6 +6363,7 @@ exports.register_c_yuno = register_c_yuno;
6341
6363
  exports.safeSrc = safeSrc;
6342
6364
  exports.sdata_flag_t = sdata_flag_t;
6343
6365
  exports.send_http_json_post = send_http_json_post;
6366
+ exports.set_log_callback = set_log_callback;
6344
6367
  exports.set_remote_log_functions = set_remote_log_functions;
6345
6368
  exports.set_timeout = set_timeout;
6346
6369
  exports.set_timeout_periodic = set_timeout_periodic;