@goldfishjs/composition-api
Advanced tools
Comparing version 0.0.18 to 1.0.0
@@ -16,2 +16,3 @@ const libraryName = require('./package.json').name; | ||
setupApp: `${codeDir}/setupApp`, | ||
Setup: `${codeDir}/setup/Setup`, | ||
useState: `${codeDir}/useState`, | ||
@@ -30,4 +31,5 @@ useValue: `${codeDir}/useValue`, | ||
usePlugins: `${codeDir}/usePlugins`, | ||
reactive: `${codeDir}/reactive`, | ||
}[name]; | ||
}, | ||
}; |
@@ -9,2 +9,3 @@ export { default as useComponentLifeCycle } from './useComponentLifeCycle'; | ||
export * from './setupApp'; | ||
export { default as Setup } from './setup/Setup'; | ||
export { default as useState } from './useState'; | ||
@@ -21,2 +22,3 @@ export { default as useValue } from './useValue'; | ||
export { default as useWatch } from './useWatch'; | ||
export { default as useAutorun } from './useAutorun'; | ||
export { default as useAutorun } from './useAutorun'; | ||
export { default as reactive } from './reactive'; |
import _getMiniDataSetter from "@goldfishjs/reactive-connect/lib/getMiniDataSetter"; | ||
import _watchDeep from "@goldfishjs/reactive/lib/watchDeep"; | ||
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; | ||
import { reactive } from './useState'; | ||
import reactive from './reactive'; | ||
export default function integrateSetupFunctionResult(fn, setup, viewInstance, store) { | ||
@@ -31,3 +30,3 @@ setup.setStoreInstance(store); | ||
var stopList = []; | ||
stopList.push.apply(stopList, _toConsumableArray(_watchDeep(reactiveCompositionState, function (_, keyPathList, newV, oldV, options) { | ||
stopList.push(_watchDeep(reactiveCompositionState, function (obj, keyPathList, newV, oldV, options) { | ||
if (!store.isSyncDataSafe) { | ||
@@ -39,8 +38,7 @@ return; | ||
miniDataSetter.set(viewInstance, keyPathList, newV, oldV, options); | ||
miniDataSetter.set(viewInstance, obj, keyPathList, newV, oldV, options); | ||
}, { | ||
immediate: true, | ||
customWatch: store.watch.bind(store) | ||
}))); | ||
immediate: true | ||
})); | ||
return stopList; | ||
} |
@@ -74,3 +74,4 @@ import _createApp from "@goldfishjs/core/lib/view/createApp"; | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(BizAppStore).call(this)); // Mount store to the app instance. | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(BizAppStore).call(this)); | ||
_this.stopWatchDeepList = []; // Mount store to the app instance. | ||
@@ -80,3 +81,3 @@ view.store = _assertThisInitialized(_this); | ||
setup.wrap(function () { | ||
integrateSetupFunctionResult(fn, setup, view, _assertThisInitialized(_this)); | ||
_this.stopWatchDeepList = integrateSetupFunctionResult(fn, setup, view, _assertThisInitialized(_this)); | ||
}); | ||
@@ -139,2 +140,12 @@ return _this; | ||
} | ||
}, { | ||
key: "destroy", | ||
value: function destroy() { | ||
_get(_getPrototypeOf(BizAppStore.prototype), "destroy", this).call(this); | ||
this.stopWatchDeepList.forEach(function (s) { | ||
return s(); | ||
}); | ||
this.stopWatchDeepList = []; | ||
} | ||
}]); | ||
@@ -141,0 +152,0 @@ |
import checkSetupEnv from './checkSetupEnv'; | ||
import { reactive } from './useState'; | ||
import reactive from './reactive'; | ||
export default function useComputed(val) { | ||
@@ -4,0 +4,0 @@ checkSetupEnv('useComputed', ['app', 'page', 'component']); |
@@ -1,42 +0,3 @@ | ||
import _observable from "@goldfishjs/reactive/lib/observable"; | ||
import _computed from "@goldfishjs/reactive/lib/computed"; | ||
import checkSetupEnv from './checkSetupEnv'; | ||
export function reactive(obj) { | ||
var _loop = function _loop(k) { | ||
var descriptor = Object.getOwnPropertyDescriptor(obj, k); | ||
if (descriptor && !descriptor.get && !descriptor.set && typeof obj[k] === 'function') { | ||
throw new Error("Do not put function to the reactive object: ".concat(k, ".")); | ||
} | ||
if (!descriptor || !descriptor.get && !descriptor.set) { | ||
return "continue"; | ||
} | ||
var getter = descriptor.get; | ||
var setter = descriptor.set; | ||
Object.defineProperty(obj, k, { | ||
configurable: true, | ||
enumerable: true, | ||
value: { | ||
get: getter ? function () { | ||
return getter.call(obj); | ||
} : undefined, | ||
set: setter ? function (val) { | ||
return setter.call(obj, val); | ||
} : undefined | ||
} | ||
}); | ||
}; | ||
for (var k in obj) { | ||
var _ret = _loop(k); | ||
if (_ret === "continue") continue; | ||
} | ||
_computed(obj); | ||
return _observable(obj); | ||
} | ||
import reactive from './reactive'; | ||
export default function useState(val) { | ||
@@ -43,0 +4,0 @@ checkSetupEnv('useState', ['app', 'component', 'page']); |
{ | ||
"name": "@goldfishjs/composition-api", | ||
"version": "0.0.18", | ||
"version": "1.0.0", | ||
"description": "goldfish-composition-api", | ||
@@ -18,7 +18,7 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@goldfishjs/core": "^0.0.18", | ||
"@goldfishjs/plugins": "^0.0.18", | ||
"@goldfishjs/reactive": "^0.0.18", | ||
"@goldfishjs/reactive-connect": "^0.0.18", | ||
"@goldfishjs/utils": "^0.0.18", | ||
"@goldfishjs/core": "^1.0.0", | ||
"@goldfishjs/plugins": "^1.0.0", | ||
"@goldfishjs/reactive": "^1.0.0", | ||
"@goldfishjs/reactive-connect": "^1.0.0", | ||
"@goldfishjs/utils": "^1.0.0", | ||
"mini-types": "^0.1.0" | ||
@@ -25,0 +25,0 @@ }, |
@@ -9,2 +9,3 @@ export { default as useComponentLifeCycle } from './useComponentLifeCycle'; | ||
export * from './setupApp'; | ||
export { default as Setup } from './setup/Setup'; | ||
export { ISetupFunction } from './integrateSetupFunctionResult'; | ||
@@ -23,1 +24,2 @@ export { default as useState } from './useState'; | ||
export { default as useAutorun } from './useAutorun'; | ||
export { default as reactive } from './reactive'; |
import { watchDeep } from '@goldfishjs/reactive'; | ||
import { getMiniDataSetter } from '@goldfishjs/reactive-connect'; | ||
import { reactive } from './useState'; | ||
import reactive from './reactive'; | ||
import PageSetup, { SetupPageInstance, SetupPageStore } from './setup/PageSetup'; | ||
@@ -81,5 +81,5 @@ import ComponentSetup, { | ||
const stopList: (() => void)[] = []; | ||
stopList.push(...watchDeep( | ||
stopList.push(watchDeep( | ||
reactiveCompositionState, | ||
(_: any, keyPathList, newV, oldV, options) => { | ||
(obj: any, keyPathList, newV, oldV, options) => { | ||
if (!(store as any).isSyncDataSafe) { | ||
@@ -90,7 +90,6 @@ return; | ||
const miniDataSetter = getMiniDataSetter(); | ||
miniDataSetter.set(viewInstance, keyPathList, newV, oldV, options); | ||
miniDataSetter.set(viewInstance, obj, keyPathList, newV, oldV, options); | ||
}, | ||
{ | ||
immediate: true, | ||
customWatch: (store as any).watch.bind(store), | ||
}, | ||
@@ -97,0 +96,0 @@ )); |
@@ -32,2 +32,4 @@ import integrateLifeCycleMethods from './integrateLifeCycleMethods'; | ||
class BizAppStore extends AppStore { | ||
private stopWatchDeepList: (() => void)[] = []; | ||
public constructor() { | ||
@@ -40,3 +42,3 @@ super(); | ||
setup.wrap(() => { | ||
integrateSetupFunctionResult<'app'>(fn, setup, view, this); | ||
this.stopWatchDeepList = integrateSetupFunctionResult<'app'>(fn, setup, view, this); | ||
}); | ||
@@ -57,2 +59,8 @@ } | ||
} | ||
public destroy() { | ||
super.destroy(); | ||
this.stopWatchDeepList.forEach(s => s()); | ||
this.stopWatchDeepList = []; | ||
} | ||
} | ||
@@ -59,0 +67,0 @@ |
import checkSetupEnv from './checkSetupEnv'; | ||
import { reactive } from './useState'; | ||
import reactive from './reactive'; | ||
@@ -4,0 +4,0 @@ export default function useComputed<T extends Record<string, any>>(val: T): T { |
@@ -1,36 +0,4 @@ | ||
import { observable as reactiveObservable, computed as reactiveComputed } from '@goldfishjs/reactive'; | ||
import checkSetupEnv from './checkSetupEnv'; | ||
import reactive from './reactive'; | ||
export function reactive(obj: any) { | ||
for (const k in obj) { | ||
const descriptor = Object.getOwnPropertyDescriptor(obj, k); | ||
if ( | ||
descriptor | ||
&& !descriptor.get | ||
&& !descriptor.set | ||
&& typeof obj[k] === 'function' | ||
) { | ||
throw new Error(`Do not put function to the reactive object: ${k}.`); | ||
} | ||
if (!descriptor || (!descriptor.get && !descriptor.set)) { | ||
continue; | ||
} | ||
const getter = descriptor.get; | ||
const setter = descriptor.set; | ||
Object.defineProperty(obj, k, { | ||
configurable: true, | ||
enumerable: true, | ||
value: { | ||
get: getter ? () => getter.call(obj) : undefined, | ||
set: setter ? (val: any) => setter.call(obj, val) : undefined, | ||
}, | ||
}); | ||
} | ||
reactiveComputed(obj); | ||
return reactiveObservable(obj); | ||
} | ||
export default function useState<T extends Record<string, any>>(val: T): T { | ||
@@ -37,0 +5,0 @@ checkSetupEnv('useState', ['app', 'component', 'page']); |
@@ -9,2 +9,3 @@ export { default as useComponentLifeCycle } from './useComponentLifeCycle'; | ||
export * from './setupApp'; | ||
export { default as Setup } from './setup/Setup'; | ||
export { ISetupFunction } from './integrateSetupFunctionResult'; | ||
@@ -23,1 +24,2 @@ export { default as useState } from './useState'; | ||
export { default as useAutorun } from './useAutorun'; | ||
export { default as reactive } from './reactive'; |
@@ -1,4 +0,1 @@ | ||
export declare function reactive(obj: any): { | ||
[x: string]: any; | ||
}; | ||
export default function useState<T extends Record<string, any>>(val: T): T; |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
84790
104
2309
1
+ Added@goldfishjs/bridge@1.9.5(transitive)
+ Added@goldfishjs/core@1.9.5(transitive)
+ Added@goldfishjs/module-usage@1.9.6(transitive)
+ Added@goldfishjs/plugins@1.9.5(transitive)
+ Added@goldfishjs/reactive@1.9.5(transitive)
+ Added@goldfishjs/reactive-connect@1.9.5(transitive)
+ Added@goldfishjs/requester@1.9.5(transitive)
+ Added@goldfishjs/route@1.9.5(transitive)
+ Added@goldfishjs/utils@1.9.6(transitive)
+ Added@types/lodash@4.17.15(transitive)
+ Added@types/lodash-es@4.17.12(transitive)
+ Addedlodash-es@4.17.21(transitive)
- Removed@goldfishjs/bridge@0.0.18(transitive)
- Removed@goldfishjs/core@0.0.18(transitive)
- Removed@goldfishjs/plugins@0.0.18(transitive)
- Removed@goldfishjs/reactive@0.0.18(transitive)
- Removed@goldfishjs/reactive-connect@0.0.18(transitive)
- Removed@goldfishjs/requester@0.0.18(transitive)
- Removed@goldfishjs/route@0.0.18(transitive)
- Removed@goldfishjs/utils@0.0.18(transitive)
- Removedlodash.omit@4.5.0(transitive)
- Removedlodash.pick@4.4.0(transitive)
Updated@goldfishjs/core@^1.0.0
Updated@goldfishjs/plugins@^1.0.0
Updated@goldfishjs/reactive@^1.0.0
Updated@goldfishjs/utils@^1.0.0