Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/core/component/engines/vue3/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,17 @@ export function getComponent(meta: ComponentMeta): ComponentOptions<typeof Compo
ctx.$vueWatch = this.$watch.bind(this);
init.beforeDataCreateState(ctx);

const emitter: Function = (_: unknown, handler: WatchHandler) => {
// eslint-disable-next-line @v4fire/unbound-method
const {unwatch} = watch(ctx.$fields, {deep: true, immediate: true}, handler);
return unwatch;
};

ctx.$async.on(emitter, 'mutation', watcher, {
group: 'watchers:suspend'
});
if (meta.hasForceUpdateFields) {
const emitter: Function = (_: unknown, handler: WatchHandler) => {
// eslint-disable-next-line @v4fire/unbound-method
const {unwatch} = watch(ctx.$fields, {deep: true, immediate: true}, handler);
return unwatch;
};

ctx.$async.on(emitter, 'mutation', watcher, {
group: 'watchers:suspend'
});
}

return SSR ? {} : ctx.$fields;

Expand Down
1 change: 1 addition & 0 deletions src/core/component/meta/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function createMeta(component: ComponentConstructorInfo): ComponentMeta {
tiedFields: {},
systemFields: {},
computedFields: {},
hasForceUpdateFields: false,

methods: {},
accessors: {},
Expand Down
4 changes: 4 additions & 0 deletions src/core/component/meta/fill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ export function fillMeta(

[meta.systemFields, meta.fields].forEach((field) => {
Object.entries(field).forEach(([key, field]) => {
if (field?.forceUpdate === true) {
meta.hasForceUpdateFields = true;
}

field?.watchers?.forEach((watcher) => {
if (isFunctional && watcher.functional === false) {
return;
Expand Down
5 changes: 5 additions & 0 deletions src/core/component/meta/interface/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ export interface ComponentMeta {
*/
tiedFields: Dictionary<string>;

/**
* True, if the component has fields with force update option
*/
hasForceUpdateFields: boolean;

/**
* A dictionary that contains the accessor methods of the component that support caching or watching
*/
Expand Down
4 changes: 2 additions & 2 deletions src/core/component/watch/bind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function bindRemoteWatchers(component: ComponentInterface, params?: BindR
// True if the method has been invoked with passing the custom async instance as a property
customAsync = $a !== unsafe.$async;

// Iterate over all registered watchers and listeners and initialize their
// Iterate over all registered watchers and listeners and initialize them
Object.entries(watchersMap).forEach(([watchPath, watchers]) => {
if (watchers == null) {
return;
Expand Down Expand Up @@ -139,7 +139,7 @@ export function bindRemoteWatchers(component: ComponentInterface, params?: BindR
// Currently, we need to create a wrapper for our handler because there
// are some conditions associated with the watcher:
//
// 1. It may or may doesn't provide arguments from the listened event.
// 1. It may or may not provide arguments from the listened event.
// 2. The handler can be specified either as a function or as a component method name.
//
// Additionally, we have two different scenarios:
Expand Down
4 changes: 2 additions & 2 deletions src/core/component/watch/component-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import type { ComponentInterface, RawWatchHandler } from 'core/component/interfa
export function implementComponentWatchAPI(component: ComponentInterface): void {
const {
unsafe,
unsafe: {$async: $a, meta: {computedFields, watchDependencies, watchPropDependencies, params}},
unsafe: {$async: $a, meta: {computedFields, watchDependencies, watchPropDependencies, params, hasForceUpdateFields}},
$renderEngine: {proxyGetters}
} = component;

Expand Down Expand Up @@ -171,7 +171,7 @@ export function implementComponentWatchAPI(component: ComponentInterface): void
let
fieldsWatcher;

if (isFunctional) {
if (isFunctional || !hasForceUpdateFields) {
// Don't force watching of fields until it becomes necessary
fieldsInfo.value[watcherInitializer] = () => {
delete fieldsInfo.value[watcherInitializer];
Expand Down