Skip to content

Commit

Permalink
chore!: support renaming Function.prototype.once to memoize
Browse files Browse the repository at this point in the history
  • Loading branch information
gretzkiy committed Dec 25, 2024
1 parent 87fa84c commit 4666f80
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ Changelog
_Note: Gaps between patch versions are faulty, broken or test releases._

## v4.0.0-beta.172 (2024-12-25)

#### :boom: Breaking Change

* Updated `@v4fire/core` to version `4.0.0-alpha.54` with renaming `Function.prototype.once` to `memoize`

## v4.0.0-beta.171 (2024-12-23)

#### :house: Internal
Expand Down
4 changes: 2 additions & 2 deletions src/components/directives/bind-with/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* https://github.com/V4Fire/Client/blob/master/LICENSE
*/

import type { EventEmitterLike, PromiseLikeP } from 'core/async';
import type { EventEmitterLikeP, PromiseLikeP } from 'core/async';

import type { DirectiveBinding } from 'core/component/engines';
import type { WatchOptions } from 'core/component/interface';
Expand Down Expand Up @@ -62,7 +62,7 @@ export interface EventListener<A extends any[]> extends Handle<A> {
/**
* An event emitter to listen
*/
emitter?: EventEmitterLike | EventEmitterLike['on'];
emitter?: EventEmitterLikeP;

/**
* The event name to listen for, or a list of such events
Expand Down
1 change: 1 addition & 0 deletions src/components/directives/bind-with/test/unit/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ test.describe('components/directives/bind-with', () => {
const el = await renderDirective(page, {
emitter: (event: string, listener: AnyFunction) => {
document.body.addEventListener(event, listener);
return undefined;
},

on: 'testEvent'
Expand Down
2 changes: 1 addition & 1 deletion src/components/super/i-block/base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ export default abstract class iBlockBase extends iBlockFriends {
// eslint-disable-next-line prefer-const
unwatch: Nullable<Function>;

const emitter: Function = (_: any, wrappedHandler: RawWatchHandler<typeof that, T>) => {
const emitter = (_: any, wrappedHandler: RawWatchHandler<typeof that, T>) => {
wrappedHandler['originalLength'] = handler['originalLength'] ?? handler.length;
handler = wrappedHandler;

Expand Down
2 changes: 1 addition & 1 deletion src/core/component/engines/vue3/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function getComponent(meta: ComponentMeta): ComponentOptions<typeof Compo
unsafe.$vueWatch = this.$watch.bind(this);
init.beforeDataCreateState(ctx);

const emitter: Function = (_: unknown, handler: WatchHandler) => {
const emitter = (_: unknown, handler: WatchHandler) => {
// eslint-disable-next-line @v4fire/unbound-method
const {unwatch} = watch(unsafe.$fields, {deep: true, immediate: true}, handler);
return unwatch;
Expand Down
6 changes: 3 additions & 3 deletions src/core/component/init/states/before-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export function beforeCreateState(

let fn = () => ('getRoot' in ctx ? ctx.getRoot?.() : null) ?? ctx.$root;

fn = fn.once();
fn = fn.memoize();

Object.defineProperty(ctx, $getRoot, {
configurable: true,
Expand Down Expand Up @@ -163,7 +163,7 @@ export function beforeCreateState(
return targetCtx[$getParent];
}

let fn: CanUndef<Function>;
let fn: CanUndef<AnyFunction>;

if (restArgs != null) {
// VNODE
Expand All @@ -179,7 +179,7 @@ export function beforeCreateState(
fn = () => ctx;
}

fn = fn.once();
fn = fn.memoize();

Object.defineProperty(targetCtx, $getParent, {
configurable: true,
Expand Down
2 changes: 1 addition & 1 deletion src/core/init/dependencies/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export function* createDependencyIterator(
wait: expandedWait
};

expandedDependency.fn = expandedDependency.fn.once();
expandedDependency.fn = expandedDependency.fn.memoize();
expandedDependencies.set(dependency, expandedDependency);

return expandedDependency;
Expand Down

0 comments on commit 4666f80

Please sign in to comment.