@yuneta/gobj-js 7.16.0 → 7.16.2

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.
@@ -3270,7 +3270,9 @@ var gobjJs = (function(exports) {
3270
3270
  return 0;
3271
3271
  }
3272
3272
  /************************************************************
3273
- * String element = 1 if not empty string
3273
+ * How much content a json carries: elements of a container,
3274
+ * 1 for a non-empty string, 0 for everything else
3275
+ * (null/undefined, scalars). C twin: json_size() in helpers.h.
3274
3276
  ************************************************************/
3275
3277
  function json_size(a) {
3276
3278
  if (is_object(a)) return Object.keys(a).length;
@@ -3279,6 +3281,22 @@ var gobjJs = (function(exports) {
3279
3281
  else return 0;
3280
3282
  }
3281
3283
  /************************************************************
3284
+ * "There is nothing usable here": null/undefined, {}, [],
3285
+ * "" and any scalar. C twin: empty_json() in helpers.h,
3286
+ * where it is the guard to write instead of `if(!jn)` --
3287
+ * there an absent DTP_JSON is json_null(), a valid pointer.
3288
+ * Here `if(!x)` happens to work, and that difference is what
3289
+ * a port across the two runtimes gets wrong: write the same
3290
+ * question in both.
3291
+ *
3292
+ * The other question -- "absent or explicitly null", C's
3293
+ * json_absent() -- is is_null() here, since javascript has
3294
+ * no second null to tell apart.
3295
+ ************************************************************/
3296
+ function empty_json(a) {
3297
+ return json_size(a) === 0;
3298
+ }
3299
+ /************************************************************
3282
3300
  * Return if a value is an object (excluding arrays & null)
3283
3301
  ************************************************************/
3284
3302
  function is_object(value) {
@@ -6724,14 +6742,20 @@ var gobjJs = (function(exports) {
6724
6742
  gobj_send_event(gobj, iev_event, iev_kw, gobj);
6725
6743
  return 0;
6726
6744
  }
6727
- let gobj_service = gobj_find_service(iev_dst_service, true);
6728
- if (gobj_service) {
6729
- if (gobj_has_event(gobj_service, iev_event, event_flag_t.EVF_PUBLIC_EVENT)) gobj_send_event(gobj_service, iev_event, iev_kw, gobj);
6730
- else {
6745
+ if (!empty_string(iev_dst_service)) {
6746
+ let gobj_service = gobj_find_service(iev_dst_service, false);
6747
+ if (!gobj_service) {
6748
+ log_warning(`${gobj_short_name(gobj)}: event for a service that is gone, DROPPED: service '${iev_dst_service}', ev '${iev_event}'`);
6749
+ return 0;
6750
+ }
6751
+ if (!gobj_has_event(gobj_service, iev_event, event_flag_t.EVF_PUBLIC_EVENT)) {
6731
6752
  log_error(`${gobj_short_name(gobj)}: Service found but no event or not public, service '${gobj_short_name(gobj_service)}', ev '${iev_event}'`);
6732
6753
  return -1;
6733
6754
  }
6734
- } else if (gobj_is_pure_child(gobj)) gobj_send_event(gobj_parent(gobj), iev_event, iev_kw, gobj);
6755
+ gobj_send_event(gobj_service, iev_event, iev_kw, gobj);
6756
+ return 0;
6757
+ }
6758
+ if (gobj_is_pure_child(gobj)) gobj_send_event(gobj_parent(gobj), iev_event, iev_kw, gobj);
6735
6759
  else gobj_publish_event(gobj, iev_event, iev_kw);
6736
6760
  return 0;
6737
6761
  }
@@ -6908,6 +6932,7 @@ var gobjJs = (function(exports) {
6908
6932
  exports.debounce = debounce;
6909
6933
  exports.delete_from_list = delete_from_list;
6910
6934
  exports.duplicate_objects = duplicate_objects;
6935
+ exports.empty_json = empty_json;
6911
6936
  exports.empty_string = empty_string;
6912
6937
  exports.escapeHtml = escapeHtml;
6913
6938
  exports.event_flag_t = event_flag_t;