statebus 7.0.9 → 7.0.11

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/client-library.js CHANGED
@@ -2,7 +2,6 @@
2
2
  var websocket_prefix = (clientjs_option('websocket_path')
3
3
  || '_connect_to_statebus_')
4
4
 
5
- var react_render = ReactDOM.render
6
5
  // make_client_statebus_maker()
7
6
  window.bus = window.statebus()
8
7
  bus.label = 'bus'
@@ -183,7 +182,7 @@
183
182
  headers: {accept: 'application/json'},
184
183
  signal: aborter.signal
185
184
  }
186
- ).andThen( function (x) {
185
+ ).andThen( function (new_version) {
187
186
  // New update received!
188
187
  if (subscriptions[key].status === 'connecting') {
189
188
  console.log('%c[*] opened ' + key,
@@ -196,7 +195,7 @@
196
195
  // Return the update
197
196
  t.return({
198
197
  key: key,
199
- val: add_prefixes(JSON.parse(x.body))
198
+ val: add_prefixes(JSON.parse(new_version.body))
200
199
  })
201
200
  }).catch( function (e) {
202
201
  if (subscriptions[key].status === 'aborted') {
@@ -784,7 +783,9 @@
784
783
  // This one is for react v17+.
785
784
  function make_fixed_textbox (tagname) {
786
785
  // `tagname` can be either "input" or "textarea"
787
- return createReactClass({
786
+
787
+ // Create a special component
788
+ var component = createReactClass({
788
789
  getInitialState: function() {
789
790
  return {value: this.props.value}
790
791
  },
@@ -796,25 +797,43 @@
796
797
  if (this.props.value)
797
798
  this.setState({value: e.target.value})
798
799
  },
800
+ onInput: function(e) {
801
+ this.props.onInput && this.props.onInput(e)
802
+ if (this.props.value)
803
+ this.setState({value: e.target.value})
804
+ },
799
805
  render: function() {
800
- var new_props = {}
801
- for (var k in this.props)
802
- if (this.props.hasOwnProperty(k))
803
- new_props[k] = this.props[k]
804
- if (this.state.hasOwnProperty('value'))
805
- new_props.value = this.state.value
806
- new_props.onChange = this.onChange
806
+ var new_props = {
807
+ ...this.props,
808
+ ref: this.props.forwarded_ref // We had to rename ref
809
+ }
810
+ delete new_props.forwarded_ref // Delete the old name
811
+
812
+ // Now replace any onChange or onInput with our wrapper handlers
813
+ if (new_props.hasOwnProperty('onChange'))
814
+ new_props.onChange = this.onChange
815
+ if (new_props.hasOwnProperty('onInput'))
816
+ new_props.onInput = this.onInput
817
+
807
818
  return React.createElement(tagname, new_props)
808
819
  }
809
820
  })
821
+
822
+ // But react components don't pass through the `ref` prop by default,
823
+ // so we have to do that with this special function and rename it to
824
+ // forwarded_ref temporarily:
825
+ return React.forwardRef((props, ref) => {
826
+ return React.createElement(component, {...props, forwarded_ref: ref})
827
+ })
810
828
  }
811
829
 
812
830
  // We create special functions for INPUT and TEXTAREA, because they
813
831
  // have to do extra work to maintain the cursor when we use statebus
814
832
  // instead of React's setState() for state updates.
815
- bus.libs.react17.input = make_fixed_textbox('input')
816
- bus.libs.react17.textarea = make_fixed_textbox('textarea')
817
-
833
+ if (window.React && !React.createClass && window.createReactClass) {
834
+ bus.libs.react17.input = make_fixed_textbox('input')
835
+ bus.libs.react17.textarea = make_fixed_textbox('textarea')
836
+ }
818
837
  function autodetect_args (func) {
819
838
  if (func.args) return
820
839
 
@@ -962,6 +981,7 @@
962
981
  return widge(props, children)
963
982
  }
964
983
 
984
+ // var react_render = ReactDOM.render
965
985
  // window.users_widgets = users_widgets
966
986
  // function load_widgets () {
967
987
  // for (var w in users_widgets) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "statebus",
3
- "version": "7.0.9",
3
+ "version": "7.0.11",
4
4
  "description": "Synchronize state.",
5
5
  "main": "statebus.js",
6
6
  "scripts": {
package/statebus.js CHANGED
@@ -1034,6 +1034,9 @@
1034
1034
  // funk.react().
1035
1035
  //
1036
1036
  // ...which will make it re-run with the original arg1 and arg2 .
1037
+ //
1038
+ // Each subsequent time you call f(arg1, arg2), it will change the
1039
+ // remembered args and re-run the funk.
1037
1040
  function funk () {
1038
1041
  console.assert(executing_funk === global_funk
1039
1042
  || executing_funk !== funk, 'Recursive funk', funk.func)