Skip to content

Commit

Permalink
feat(services): decouple the EventPubSubService to separate package
Browse files Browse the repository at this point in the history
- in order to use this EventPubSubService in other framework (like Angular-Slickgrid) without rewriting the same code, we can simply extract this into a brand new package and reuse it in the other framework
  • Loading branch information
ghiscoding committed Jun 28, 2021
1 parent 41855eb commit 9f51665
Show file tree
Hide file tree
Showing 24 changed files with 614 additions and 442 deletions.
8 changes: 4 additions & 4 deletions examples/webpack-demo-vanilla-bundle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,24 @@
"devDependencies": {
"@types/jquery": "^3.5.5",
"@types/moment": "^2.13.0",
"@types/node": "^15.12.4",
"@types/node": "^15.12.5",
"@types/webpack": "^5.28.0",
"clean-webpack-plugin": "^3.0.0",
"copy-webpack-plugin": "^9.0.0",
"copy-webpack-plugin": "^9.0.1",
"css-loader": "^5.2.6",
"file-loader": "^6.2.0",
"fork-ts-checker-webpack-plugin": "^6.2.12",
"html-loader": "^2.1.2",
"html-webpack-plugin": "5.3.2",
"mini-css-extract-plugin": "^1.6.0",
"mini-css-extract-plugin": "^1.6.2",
"rxjs": "^7.1.0",
"sass": "^1.35.1",
"sass-loader": "^12.1.0",
"style-loader": "^3.0.0",
"ts-loader": "^9.2.3",
"ts-node": "^10.0.0",
"url-loader": "^4.1.1",
"webpack": "^5.40.0",
"webpack": "^5.41.0",
"webpack-cli": "^4.7.2",
"webpack-dev-server": "^3.11.2"
}
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@
},
"devDependencies": {
"@types/jest": "^26.0.23",
"@types/node": "^15.12.4",
"@typescript-eslint/eslint-plugin": "^4.28.0",
"@typescript-eslint/parser": "^4.28.0",
"@types/node": "^15.12.5",
"@typescript-eslint/eslint-plugin": "^4.28.1",
"@typescript-eslint/parser": "^4.28.1",
"cypress": "^7.6.0",
"eslint": "^7.29.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-prefer-arrow": "^1.2.3",
"jest": "^27.0.5",
"jest-cli": "^27.0.5",
"jest-environment-jsdom": "^27.0.5",
"jest": "^27.0.6",
"jest-cli": "^27.0.6",
"jest-environment-jsdom": "^27.0.6",
"jest-extended": "^0.11.5",
"jsdom": "^16.6.0",
"jsdom-global": "^3.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"autoprefixer": "^10.2.6",
"copyfiles": "^2.4.1",
"cross-env": "^7.0.3",
"mini-css-extract-plugin": "^1.6.0",
"mini-css-extract-plugin": "^1.6.2",
"nodemon": "^2.0.7",
"npm-run-all": "^4.1.5",
"postcss": "^8.3.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ $header-menu-button-icon-font-size: 26px !default;
$header-menu-button-icon-color: #706e6b !default;
$header-menu-button-icon: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" fill="#{encodecolor($header-menu-button-icon-color)}" viewBox="0 0 24 24"><path d="M22 8.2l-9.5 9.6c-.3.2-.7.2-1 0L2 8.2c-.2-.3-.2-.7 0-1l1-1c.3-.3.8-.3 1.1 0l7.4 7.5c.3.3.7.3 1 0l7.4-7.5c.3-.2.8-.2 1.1 0l1 1c.2.3.2.7 0 1z"></path></svg>') !default;
$header-menu-button-margin-right: 8px !default;
$header-menu-display: inline-block !default;
// $header-menu-display: inline-block !default;
$header-menu-icon-margin-right: 6px !default;
$header-menu-icon-font-size: $icon-width !default;
$header-menu-icon-width: $icon-width !default;
Expand Down
21 changes: 21 additions & 0 deletions packages/event-pub-sub/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/)
[![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)](https://lerna.js.org/)
[![npm](https://img.shields.io/npm/v/@slickgrid-universal/event-pub-sub.svg?color=forest)](https://www.npmjs.com/package/@slickgrid-universal/event-pub-sub)
[![npm](https://img.shields.io/npm/dy/@slickgrid-universal/event-pub-sub?color=forest)](https://www.npmjs.com/package/@slickgrid-universal/event-pub-sub)

[![Actions Status](https://github.com/ghiscoding/slickgrid-universal/workflows/CI%20Build/badge.svg)](https://github.com/ghiscoding/slickgrid-universal/actions)
[![Cypress.io](https://img.shields.io/badge/tested%20with-Cypress-04C38E.svg)](https://www.cypress.io/)
[![jest](https://jestjs.io/img/jest-badge.svg)](https://github.com/facebook/jest)
[![codecov](https://codecov.io/gh/ghiscoding/slickgrid-universal/branch/master/graph/badge.svg)](https://codecov.io/gh/ghiscoding/slickgrid-universal)

## Event PubSub Service
#### @slickgrid-universal/event-pub-sub

A very simple Vanilla Implementation of an Event PubSub Service to do simple publish/subscribe inter-communication while optionally providing data as well.

### External Dependencies
- [DOM Purify](https://github.com/cure53/DOMPurify) to sanitize HTML text

### Installation
Follow the instruction provided in the main [README](https://github.com/ghiscoding/slickgrid-universal#installation)
49 changes: 49 additions & 0 deletions packages/event-pub-sub/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "@slickgrid-universal/event-pub-sub",
"version": "0.14.1",
"description": "Simple Vanilla Implementation of an Event PubSub Service to do simply publish/subscribe inter-communication while optionally providing data in the event",
"main": "dist/commonjs/index.js",
"browser": "src/index.ts",
"module": "dist/esm/index.js",
"types": "dist/commonjs/index.d.ts",
"typings": "dist/commonjs/index.d.ts",
"publishConfig": {
"access": "public"
},
"directories": {
"src": "src"
},
"scripts": {
"build": "cross-env tsc --build",
"postbuild": "npm-run-all bundle:commonjs",
"build:watch": "cross-env tsc --incremental --watch",
"dev": "run-s build",
"dev:watch": "run-p build:watch",
"bundle": "run-p bundle:commonjs bundle:esm",
"bundle:commonjs": "tsc --project tsconfig.bundle.json --outDir dist/commonjs --module commonjs",
"bundle:esm": "cross-env tsc --project tsconfig.bundle.json --outDir dist/esm --module esnext --target es2018",
"prebundle": "npm-run-all delete:dist",
"delete:dist": "cross-env rimraf --maxBusyTries=10 dist",
"package:add-browser-prop": "cross-env node ../change-package-browser.js --add-browser=true --folder-name=event-pub-sub",
"package:remove-browser-prop": "cross-env node ../change-package-browser.js --remove-browser=true --folder-name=event-pub-sub"
},
"author": "Ghislain B.",
"license": "MIT",
"engines": {
"node": ">=14.15.0",
"npm": ">=6.14.8"
},
"browserslist": [
"last 2 version",
"> 1%",
"not dead"
],
"dependencies": {
"@slickgrid-universal/common": "^0.14.1"
},
"devDependencies": {
"cross-env": "^7.0.3",
"npm-run-all": "^4.1.5",
"rimraf": "^3.0.2"
}
}
2 changes: 2 additions & 0 deletions packages/event-pub-sub/src/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
index.ts
**/*.*
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EventPubSubService } from '../eventPubSub.service';
import { EventPubSubService } from './eventPubSub.service';
import { EventNamingStyle } from '@slickgrid-universal/common';

describe('EventPubSub Service', () => {
Expand Down
11 changes: 11 additions & 0 deletions packages/event-pub-sub/src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as entry from './index';

describe('Testing library entry point', () => {
it('should have an index entry point defined', () => {
expect(entry).toBeTruthy();
});

it('should have all exported object defined', () => {
expect(typeof entry.EventPubSubService).toBe('function');
});
});
1 change: 1 addition & 0 deletions packages/event-pub-sub/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './eventPubSub.service';
14 changes: 14 additions & 0 deletions packages/event-pub-sub/tsconfig.bundle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "../tsconfig.bundle.json",
"compilerOptions": {
"typeRoots": [
"../typings",
"../../node_modules/@types"
],
"outDir": "dist/commonjs"
},
"include": [
"../typings",
"**/*"
]
}
24 changes: 24 additions & 0 deletions packages/event-pub-sub/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"extends": "../tsconfig.base.json",
"compileOnSave": false,
"compilerOptions": {
"rootDir": "src",
"declarationDir": "dist/esm",
"outDir": "dist/esm",
"typeRoots": [
"typings"
]
},
"exclude": [
"dist",
"node_modules",
"**/*.spec.ts"
],
"filesGlob": [
"./src/**/*.ts"
],
"include": [
"src/**/*.ts",
"typings/**/*.ts"
]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

import { PaginationService, SharedService, SlickGrid, GridOption, Locale } from '@slickgrid-universal/common';
import { EventPubSubService } from '@slickgrid-universal/event-pub-sub';

import { TranslateServiceStub } from '../../../../test/translateServiceStub';
import { EventPubSubService } from '../../../vanilla-bundle/src/services/eventPubSub.service';
import { SlickPaginationComponent } from '../slick-pagination.component';

function removeExtraSpaces(text: string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

import { PaginationService, SharedService, SlickGrid, GridOption } from '@slickgrid-universal/common';
import { EventPubSubService } from '@slickgrid-universal/event-pub-sub';

import { TranslateServiceStub } from '../../../../test/translateServiceStub';
import { EventPubSubService } from '../../../vanilla-bundle/src/services/eventPubSub.service';
import { SlickPaginationComponent } from '../slick-pagination.component';

function removeExtraSpaces(text: string) {
Expand Down
Binary file not shown.
3 changes: 2 additions & 1 deletion packages/vanilla-bundle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@slickgrid-universal/composite-editor-component": "^0.14.1",
"@slickgrid-universal/custom-footer-component": "^0.14.1",
"@slickgrid-universal/empty-warning-component": "^0.14.1",
"@slickgrid-universal/event-pub-sub": "^0.14.1",
"@slickgrid-universal/excel-export": "^0.14.1",
"@slickgrid-universal/pagination-component": "^0.14.1",
"@slickgrid-universal/text-export": "^0.14.1",
Expand All @@ -64,6 +65,6 @@
"npm-run-all": "^4.1.5",
"rimraf": "^3.0.2",
"ts-loader": "^9.2.3",
"webpack": "^5.40.0"
"webpack": "^5.41.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ import {
CurrentPinning,
} from '@slickgrid-universal/common';
import { GraphqlService, GraphqlPaginatedResult, GraphqlServiceApi, GraphqlServiceOption } from '@slickgrid-universal/graphql';
import { EventPubSubService } from '@slickgrid-universal/event-pub-sub';
import { SlickCompositeEditorComponent } from '@slickgrid-universal/composite-editor-component';
import * as formatterUtilities from '@slickgrid-universal/common/dist/commonjs/formatters/formatterUtilities';

import { SlickVanillaGridBundle } from '../slick-vanilla-grid-bundle';
import { EventPubSubService } from '../../services/eventPubSub.service';
import { TextExportService } from '../../services/textExport.service';
import { TranslateServiceStub } from '../../../../../test/translateServiceStub';
import { HttpStub } from '../../../../../test/httpClientStub';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ import {
emptyElement,
GetSlickEventType,
} from '@slickgrid-universal/common';
import { EventPubSubService } from '@slickgrid-universal/event-pub-sub';
import { SlickCompositeEditorComponent } from '@slickgrid-universal/composite-editor-component';
import { SlickEmptyWarningComponent } from '@slickgrid-universal/empty-warning-component';
import { SlickFooterComponent } from '@slickgrid-universal/custom-footer-component';
import { SlickPaginationComponent } from '@slickgrid-universal/pagination-component';

import { EventPubSubService } from '../services/eventPubSub.service';
import { TextExportService } from '../services/textExport.service';
import { ResizerService } from '../services/resizer.service';
import { SalesforceGlobalGridOptions } from '../salesforce-global-grid-options';
Expand Down
6 changes: 4 additions & 2 deletions packages/vanilla-bundle/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Aggregators, Editors, Enums, Filters, Formatters, GroupTotalFormatters, SortComparers, Utilities } from '@slickgrid-universal/common';
import { BindingService } from '@slickgrid-universal/binding';
import { EventPubSubService } from '@slickgrid-universal/event-pub-sub';
import { SlickCompositeEditorComponent } from '@slickgrid-universal/composite-editor-component';
import { SlickEmptyWarningComponent } from '@slickgrid-universal/empty-warning-component';
import { SlickPaginationComponent } from '@slickgrid-universal/pagination-component';
import { SlickVanillaGridBundle } from './components/slick-vanilla-grid-bundle';

const Slicker = {
Expand All @@ -23,8 +25,8 @@ if (typeof window !== 'undefined') {
}

export { BindingService };
export { Aggregators, Editors, Enums, Filters, Formatters, GroupTotalFormatters, SortComparers, Utilities };
export { SlickCompositeEditorComponent, SlickEmptyWarningComponent, SlickVanillaGridBundle }; // export the custom components & interfaces
export { Aggregators, Editors, Enums, EventPubSubService, Filters, Formatters, GroupTotalFormatters, SortComparers, Utilities };
export { SlickCompositeEditorComponent, SlickEmptyWarningComponent, SlickPaginationComponent, SlickVanillaGridBundle }; // export the custom components & interfaces
export { Slicker };
export * from './interfaces/index';
export * from './services/index';
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Column, Editors, FieldType, GridOption, SlickGrid, SlickNamespace, } from '@slickgrid-universal/common';
import { EventPubSubService } from '../eventPubSub.service';
import { EventPubSubService } from '@slickgrid-universal/event-pub-sub';

import { ResizerService } from '../resizer.service';

declare const Slick: SlickNamespace;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GridOption, SharedService, SlickGrid, SlickDataView, PubSubService } from '@slickgrid-universal/common';
import { GridOption, SlickGrid, SlickDataView, PubSubService } from '@slickgrid-universal/common';

import { ContainerServiceStub } from '../../../../../test/containerServiceStub';
import { TextExportService } from '../textExport.service';

Expand Down
1 change: 0 additions & 1 deletion packages/vanilla-bundle/src/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './eventPubSub.service';
export * from './resizer.service';
export * from './textExport.service';
export * from './universalContainer.service';
Loading

0 comments on commit 9f51665

Please sign in to comment.