Skip to content

Commit

Permalink
feat: add events for sync and push tags
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewPattell committed Sep 4, 2024
1 parent 65e083a commit da0fd15
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 0 deletions.
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
},
"peerDependencies": {
"@lomray/consistent-suspense": ">=2.0.1",
"@lomray/event-manager": ">=2.0.2",
"react": ">=17.0.2",
"react-dom": ">=17.0.2"
}
Expand Down
9 changes: 9 additions & 0 deletions src/events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Head manager events
*/
enum Events {
PUSH_TAGS = 'head-manager:push-tags',
SYNC_META = 'head-manager:sync-meta',
}

export default Events;
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
export * from './types';

export * from './context';

export { default as TagStatus } from './tag-status';

export { default as Manager } from './manager';

export { default as Events } from './events';
6 changes: 6 additions & 0 deletions src/manager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import EventManager from '@lomray/event-manager';
import htmlParser from 'html-react-parser';
import type { ReactElement, ReactNode } from 'react';
import React, { Fragment, Children } from 'react';
import Events from './events';
import TagStatus from './tag-status';

export interface IMetaManagerTags {
Expand Down Expand Up @@ -519,6 +521,8 @@ class Manager {

prevElement = domElement;
});

EventManager.publish(Events.SYNC_META, {});
}

/**
Expand All @@ -534,6 +538,8 @@ class Manager {
isAdded ? TagStatus.synced : TagStatus.init,
);

EventManager.publish(Events.PUSH_TAGS, { elements, containerId });

// skip sync already synced tags
if (this.isServer || isAdded) {
return;
Expand Down
10 changes: 10 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { ReactNode } from 'react';
import type Events from './events';

export interface IHeadManagerEvents {
[Events.PUSH_TAGS]: {
containerId: string;
elements: ReactNode;
};
[Events.SYNC_META]: Record<string, unknown>;
}

0 comments on commit da0fd15

Please sign in to comment.