statebus 7.0.9 → 7.0.10

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.
Files changed (2) hide show
  1. package/client-library.js +27 -8
  2. package/package.json +1 -1
package/client-library.js CHANGED
@@ -784,7 +784,9 @@
784
784
  // This one is for react v17+.
785
785
  function make_fixed_textbox (tagname) {
786
786
  // `tagname` can be either "input" or "textarea"
787
- return createReactClass({
787
+
788
+ // Create a special component
789
+ var component = createReactClass({
788
790
  getInitialState: function() {
789
791
  return {value: this.props.value}
790
792
  },
@@ -796,17 +798,34 @@
796
798
  if (this.props.value)
797
799
  this.setState({value: e.target.value})
798
800
  },
801
+ onInput: function(e) {
802
+ this.props.onInput && this.props.onInput(e)
803
+ if (this.props.value)
804
+ this.setState({value: e.target.value})
805
+ },
799
806
  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
807
+ var new_props = {
808
+ ...this.props,
809
+ ref: this.props.forwarded_ref // We had to rename ref
810
+ }
811
+ delete new_props.forwarded_ref // Delete the old name
812
+
813
+ // Now replace any onChange or onInput with our wrapper handlers
814
+ if (new_props.hasOwnProperty('onChange'))
815
+ new_props.onChange = this.onChange
816
+ if (new_props.hasOwnProperty('onInput'))
817
+ new_props.onInput = this.onInput
818
+
807
819
  return React.createElement(tagname, new_props)
808
820
  }
809
821
  })
822
+
823
+ // But react components don't pass through the `ref` prop by default,
824
+ // so we have to do that with this special function and rename it to
825
+ // forwarded_ref temporarily:
826
+ return React.forwardRef((props, ref) => {
827
+ return React.createElement(component, {...props, forwarded_ref: ref})
828
+ })
810
829
  }
811
830
 
812
831
  // We create special functions for INPUT and TEXTAREA, because they
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "statebus",
3
- "version": "7.0.9",
3
+ "version": "7.0.10",
4
4
  "description": "Synchronize state.",
5
5
  "main": "statebus.js",
6
6
  "scripts": {