statebus 6.1.29 → 6.1.31

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "statebus",
3
- "version": "6.1.29",
3
+ "version": "6.1.31",
4
4
  "description": "Synchronize state.",
5
5
  "main": "statebus.js",
6
6
  "scripts": {
package/statebus.js CHANGED
@@ -663,20 +663,23 @@
663
663
 
664
664
  function pattern_matcher (pattern) {
665
665
  var param_names = []
666
- var regex = new RegExp('^' + pattern.replace(/(?<=^|\/):[^/()]+|\*/g, match => {
666
+ function replace_param (match, prefix, param, star) {
667
667
  // Replace * with .*
668
- if (match === '*') return '.*'
668
+ if (star === '*') return '.*'
669
669
 
670
670
  // Replace :foo with ([^/]+), and remember the "foo" name
671
- param_names.push(match.slice(1))
672
- return '([^/]+)'
673
- }) + '$')
671
+ param_names.push(param.slice(1))
672
+ return prefix + '([^/]+)'
673
+ }
674
+ var regex = new RegExp('^'
675
+ + pattern.replace(/(^|\/)(:[^/()]+)|(\*)/g, replace_param)
676
+ + '$')
674
677
 
675
- return path => {
678
+ return function (path) {
676
679
  var match = path.match(regex)
677
680
  if (!match) return null
678
681
  var params = {}
679
- match.slice(1).forEach((val, i) => params[param_names[i]] = val)
682
+ match.slice(1).forEach(function (val, i) { return params[param_names[i]] = val} )
680
683
  return params
681
684
  }
682
685
  }
@@ -752,7 +755,7 @@
752
755
  method: method,
753
756
  params: matches
754
757
  }
755
- result.push({method, key:handler.pattern, func:handler.funk})
758
+ result.push({method:method, key:handler.pattern, func:handler.funk})
756
759
  seen[funk_key(handler.funk)] = true
757
760
  }
758
761
  }
@@ -761,6 +764,11 @@
761
764
  }
762
765
 
763
766
  function run_handler(funck, method, arg, options) {
767
+ // If method == "save", then arg is an object {}
768
+ // If method == "fetch", then arg is a key
769
+ // If method == "forget", then arg is a key
770
+ // If method == "delete", then arg is a key
771
+
764
772
  options = options || {}
765
773
  var t = options.t,
766
774
  just_make_it = options.dont_run,
@@ -821,7 +829,7 @@
821
829
  // Fresh fetch/save/forget/delete handlers will just be regular
822
830
  // functions. We'll store their arg and transaction and let them
823
831
  // re-run until they are done re-running.
824
- function key_arg () { return ((typeof arg.key) == 'string') ? arg.key : arg }
832
+ function key_arg () { return ((typeof arg.key) === 'string') ? arg.key : arg }
825
833
  function rest_arg () { return (key_arg()).substr(binding.length-1) }
826
834
  function vars_arg () {
827
835
  var r = rest_arg()
@@ -856,8 +864,8 @@
856
864
  // Delete empty parts (this ensures that empty strings
857
865
  // will properly result in empty KSON, and allows trailing
858
866
  // commas)
859
- .filter(part => part.length)
860
- .forEach(part => {
867
+ .filter(function (part) { return part.length })
868
+ .forEach(function (part) {
861
869
  // If the part has a comma, its a key:value, otherwise
862
870
  // it's just a singleton
863
871
  var [k, v] = split_once(part, ":")
@@ -1,3 +0,0 @@
1
- import statebus from 'statebus'
2
-
3
- console.log(statebus)