@plasmicapp/react-web 0.2.133 → 0.2.134

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/dist/all.d.ts CHANGED
@@ -36,6 +36,7 @@ interface $StateSpec<T> {
36
36
  valueProp?: string;
37
37
  onChangeProp?: string;
38
38
  isArray?: boolean;
39
+ isImmutable?: boolean;
39
40
  }
40
41
  declare function useDollarState(specs: $StateSpec<any>[], props: Record<string, any>, $ctx?: Record<string, any>): any;
41
42
 
@@ -13,6 +13,7 @@ var ReactDOM__default = _interopDefault(ReactDOM);
13
13
  var dataSourcesContext = require('@plasmicapp/data-sources-context');
14
14
  var ssr = require('@react-aria/ssr');
15
15
  var focus = require('@react-aria/focus');
16
+ var clone = _interopDefault(require('clone'));
16
17
  var deepEqual = _interopDefault(require('fast-deep-equal'));
17
18
  var valtio = require('valtio');
18
19
  var utils = require('valtio/utils');
@@ -1979,7 +1980,7 @@ function initializeStateValue($$state, initialStatePath, initialSpec) {
1979
1980
  var path = _ref2.path,
1980
1981
  spec = _ref2.spec;
1981
1982
  var unsubscribe = utils.subscribeKey(_get($$state.stateValues, path.slice(-1)), path.slice(-1)[0], function () {
1982
- return set($$state.stateValues, initialStatePath, mkUntrackedValue(initialSpec.initFunc($$state.props, $state, $$state.ctx, getIndexes(path, spec))));
1983
+ return saveValue($$state, initialStatePath, initialSpec, initialSpec.initFunc($$state.props, $state, $$state.ctx, getIndexes(path, spec)));
1983
1984
  });
1984
1985
  $$state.unsubscriptionsByState[initialStateKey].push(unsubscribe);
1985
1986
  });
@@ -1988,27 +1989,25 @@ function initializeStateValue($$state, initialStatePath, initialSpec) {
1988
1989
  return initialValue;
1989
1990
  }
1990
1991
 
1991
- function saveStateInitialValue($$state, path, spec, initialValue) {
1992
- // array states are a special case.Wwe listen for changes in the array and in the array cells.
1993
- // for example: $state.people.push(...), $state.people.splice(...), $state.people[0] = ...
1994
- // that's why we need to track the array object
1995
- if (spec.isArray && Array.isArray(initialValue)) {
1996
- var array = initialValue.map(function (val) {
1997
- return mkUntrackedValue(val);
1998
- });
1999
-
2000
- set($$state.stateValues, path, array); // we need to make the array untracked for initStateValues
2001
- // so we can distinguish between stateValue and initStateValue.
2002
- // otherwise they would reference the same array.
2003
-
2004
-
2005
- set($$state.initStateValues, path, mkUntrackedValue(array));
1992
+ function saveValue($$state, path, spec, value) {
1993
+ if (spec.isImmutable) {
1994
+ set($$state.stateValues, path, mkUntrackedValue(value));
2006
1995
  } else {
1996
+ set($$state.stateValues, path, value);
1997
+ }
1998
+ }
1999
+
2000
+ function saveStateInitialValue($$state, path, spec, initialValue) {
2001
+ if (spec.isImmutable) {
2007
2002
  var untrackedValue = mkUntrackedValue(initialValue);
2008
2003
 
2009
2004
  set($$state.stateValues, path, untrackedValue);
2010
2005
 
2011
- set($$state.initStateValues, path, untrackedValue);
2006
+ set($$state.initStateValues, path, clone(untrackedValue));
2007
+ } else {
2008
+ set($$state.stateValues, path, clone(initialValue));
2009
+
2010
+ set($$state.initStateValues, path, clone(initialValue));
2012
2011
  }
2013
2012
  }
2014
2013
 
@@ -2053,8 +2052,8 @@ function useDollarState(specs, props, $ctx) {
2053
2052
  return _get($$state.stateValues, path);
2054
2053
  }
2055
2054
  },
2056
- set: function set$1(_t, _p, value) {
2057
- set($$state.stateValues, path, mkUntrackedValue(value));
2055
+ set: function set(_t, _p, value) {
2056
+ saveValue($$state, path, spec, value);
2058
2057
 
2059
2058
  if (spec.onChangeProp) {
2060
2059
  var _$$state$props$spec$o3, _$$state$props3;
@@ -2157,8 +2156,8 @@ function useCanvasDollarState(specs, props, $ctx) {
2157
2156
  get: function get() {
2158
2157
  return _get($$state.stateValues, path);
2159
2158
  },
2160
- set: function set$1(_t, _p, value) {
2161
- set($$state.stateValues, path, mkUntrackedValue(value));
2159
+ set: function set(_t, _p, value) {
2160
+ saveValue($$state, path, spec, value);
2162
2161
 
2163
2162
  if (spec.onChangeProp) {
2164
2163
  var _$$state$props$spec$o5, _$$state$props5;