lilact 0.2.0 → 0.2.1

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/README.md CHANGED
@@ -98,11 +98,10 @@ As a simple example Lilact can be used like this:
98
98
  </head>
99
99
  <body></body>
100
100
  <script type='text/jsx'>
101
-
102
- const { render, useState } = Lilact;
103
- function App({children}) {
104
- [...]
105
- return <div>Hello World</div>!
101
+ const { render } = Lilact;
102
+
103
+ function App() {
104
+ return <div>Hello World</div>;
106
105
  }
107
106
 
108
107
  render(<App/>, document.body);
@@ -5785,25 +5785,27 @@ function useState(val)
5785
5785
  * @param {Array<any>} deps - Dependency list.
5786
5786
  * @returns {Function} Memoized callback.
5787
5787
  */
5788
- function useCallback(callback, deps=[{}])
5788
+ function useCallback(callback, deps=undefined)
5789
5789
  {
5790
+ if( deps!==undefined && (typeof(deps)!=='object' || deps.constructor.name!=='Array') ) {
5791
+ throw "callback dependencies must be an array or omitted.";
5792
+ }
5793
+
5790
5794
  const hk = Lilact.useHook();
5791
5795
 
5792
5796
  if( Lilact.isEmpty(hk) ) {
5793
5797
  hk.callback = callback;
5794
- hk.deps = deps;
5795
5798
  }
5796
5799
  else {
5797
- for(let d in deps) {
5798
- if( !Lilact.defaultIsEqual(deps[d],hk.deps[d]) ) {
5799
- hk.callback = callback;
5800
+ if(deps!==undefined && hk?.deps!==undefined && Lilact.shallowEqual(deps, hk.deps)) return hk.callback;
5801
+ }
5800
5802
 
5801
- hk.deps = deps;
5802
- break;
5803
- }
5804
- }
5803
+ if(hk?.cleanup) {
5804
+ hk.cleanup();
5805
5805
  }
5806
5806
 
5807
+ hk.deps = deps;
5808
+
5807
5809
  return hk.callback;
5808
5810
  }
5809
5811
 
@@ -5970,25 +5972,25 @@ function useRef(val = null)
5970
5972
  * @param {Array<any>} [deps] - Dependency list.
5971
5973
  * @returns {void}
5972
5974
  */
5973
- function useLayoutEffect(setup, deps=[{}])
5975
+ function useLayoutEffect(setup, deps=undefined)
5974
5976
  {
5975
- if(typeof(deps)!=='object' || deps.constructor.name!=='Array') {
5976
- throw "effect dependencies must be an array or omitted.";
5977
+ if( deps!==undefined && (typeof(deps)!=='object' || deps.constructor.name!=='Array') ) {
5978
+ throw "layout effect dependencies must be an array or omitted.";
5977
5979
  }
5978
5980
 
5979
5981
  const hk = Lilact.useHook();
5980
5982
 
5981
5983
  if( !Lilact.isEmpty(hk) ) {
5982
- if(deps.every((v,i)=> v === hk.deps[i])) return;
5983
- if(hk.cleanup) {
5984
- hk.cleanup();
5985
- }
5984
+ if(deps!==undefined && hk?.deps!==undefined && Lilact.shallowEqual(deps, hk.deps)) return;
5985
+ }
5986
+
5987
+ if(hk?.cleanup) {
5988
+ hk.cleanup();
5986
5989
  }
5987
5990
 
5988
5991
  hk.deps = deps;
5989
5992
  Lilact.layout_effects.add( ()=>{ hk.cleanup = setup(); });
5990
5993
  Lilact.current_component[0].component.forceUpdate();
5991
-
5992
5994
  }
5993
5995
 
5994
5996
  /**
@@ -6000,17 +6002,18 @@ function useLayoutEffect(setup, deps=[{}])
6000
6002
  */
6001
6003
  function useEffect(setup, deps=[{}])
6002
6004
  {
6003
- if(typeof(deps)!=='object' || deps.constructor.name!=='Array') {
6005
+ if( deps!==undefined && (typeof(deps)!=='object' || deps.constructor.name!=='Array') ) {
6004
6006
  throw "effect dependencies must be an array or omitted.";
6005
6007
  }
6006
6008
 
6007
6009
  const hk = Lilact.useHook();
6008
6010
 
6009
6011
  if( !Lilact.isEmpty(hk) ) {
6010
- if(deps.every((v,i)=> v === hk.deps[i])) return;
6011
- if(hk.cleanup) {
6012
- hk.cleanup();
6013
- }
6012
+ if(deps!==undefined && hk?.deps!==undefined && Lilact.shallowEqual(deps, hk.deps)) return;
6013
+ }
6014
+
6015
+ if(hk?.cleanup) {
6016
+ hk.cleanup();
6014
6017
  }
6015
6018
 
6016
6019
  hk.deps = deps;
@@ -6025,24 +6028,21 @@ function useEffect(setup, deps=[{}])
6025
6028
  * @param {Array<any>} deps - Dependency list.
6026
6029
  * @returns {any} Memoized value.
6027
6030
  */
6028
- function useMemo(fn,deps=[])
6031
+ function useMemo(fn,deps=undefined)
6029
6032
  {
6033
+ if( deps!==undefined && (typeof(deps)!=='object' || deps.constructor.name!=='Array') ) {
6034
+ throw "memo dependencies must be an array or omitted.";
6035
+ }
6036
+
6030
6037
  const hk = Lilact.useHook();
6031
6038
 
6032
- if( Lilact.isEmpty(hk) ) {
6033
- hk.deps = deps;
6034
- hk.value = fn();
6035
- }
6036
- else {
6037
- for(let d in deps) {
6038
- if( !Lilact.defaultIsEqual(deps[d],hk.deps[d]) ) {
6039
- hk.deps = deps;
6040
- hk.value = fn(hk.value);
6041
- break;
6042
- }
6043
- }
6039
+ if( !Lilact.isEmpty(hk) ) {
6040
+ if(deps!==undefined && hk?.deps!==undefined && Lilact.shallowEqual(deps, hk.deps)) return hk.value;
6044
6041
  }
6045
6042
 
6043
+ hk.deps = deps;
6044
+ hk.value = fn(hk.value);
6045
+
6046
6046
  return hk.value;
6047
6047
  }
6048
6048
 
@@ -6191,16 +6191,16 @@ function forwardRef(render)
6191
6191
  */
6192
6192
  function useImperativeHandle(ref, factory, deps)
6193
6193
  {
6194
+ if(deps!==undefined && ref?.deps!==undefined && Lilact.shallowEqual(deps, ref.deps)) return;
6195
+
6196
+ ref.deps = deps;
6197
+
6194
6198
  Lilact.setTimeout( ()=>{
6195
- if( !Lilact.defaultIsEqual(deps[d],hk.deps[d]) ) {
6196
-
6197
- hk.deps = deps;
6198
- if(typeof ref.current !== object) {
6199
- ref.current = {};
6200
- }
6201
- Object.assign( ref.current, factory(), 0 );
6202
- }
6203
- });
6199
+ if(typeof ref?.current !== 'object') {
6200
+ ref.current = {};
6201
+ }
6202
+ Object.assign( ref.current, factory(), 0 );
6203
+ });
6204
6204
  }
6205
6205
 
6206
6206