Skip to content

Commit

Permalink
refactor(mse): dramatic code simplification (#167)
Browse files Browse the repository at this point in the history
BREAKING CHANGES: Most packages are now exporting modules with the "Flo" prefix.
  • Loading branch information
patrickmichalina authored Jun 27, 2019
1 parent 463528f commit d1940a0
Show file tree
Hide file tree
Showing 42 changed files with 336 additions and 511 deletions.
12 changes: 6 additions & 6 deletions projects/flosportsinc/ng-ad-block/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@ Provides a service to detect if an ad-blocker is in use.
npm i @flosportsinc/ng-ad-block
```

Inside your `BrowserModule` (or `AppModule` if you are not using a universal server) install `AdBlockBrowserModule` like so:
Inside your `BrowserModule` (or `AppModule` if you are not using a universal server) install `FloAdBlockBrowserModule` like so:

```js
import { NgModule } from '@angular/core'
import { AdBlockBrowserModule } from '@flosportsinc/ng-universal-services/ad-block'
import { FloAdBlockBrowserModule } from '@flosportsinc/ng-universal-services/ad-block'

@NgModule({
imports: [
AdBlockBrowserModule.usingUrl('http://mysite.com/ads.js')
FloAdBlockBrowserModule.usingUrl('http://mysite.com/ads.js')
]
})
export class AppBrowserModule { }
```

You will need to provide an API endpoint that return a simple 200 response object. In this example we use "http://mysite.com/ads.js". It is important to have the word "ad" somewhere in the url.

If you have a Universal app you will need to include the `AdBlockServerModule` in `AppServerModule` like so:
If you have a Universal app you will need to include the `FloAdBlockServerModule` in `AppServerModule` like so:

```js
import { NgModule } from '@angular/core'
import { AdBlockServerModule } from '@flosportsinc/ng-universal-services/ad-block'
import { FloAdBlockServerModule } from '@flosportsinc/ng-universal-services/ad-block'

@NgModule({
imports: [
AdBlockServerModule
FloAdBlockServerModule
]
})
export class AppServerModule { }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { TestBed } from '@angular/core/testing'
import { NgModule } from '@angular/core'
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'
import { AdBlockBrowserModule } from './ad-block.browser.module'
import { FloAdBlockBrowserModule } from './ad-block.browser.module'
import { AdBlockService } from '@flosportsinc/ng-ad-block'
import { take } from 'rxjs/operators'

@NgModule({
imports: [
HttpClientTestingModule,
AdBlockBrowserModule.usingUrl('http://mysite.com/ads.js')
FloAdBlockBrowserModule.usingUrl('http://mysite.com/ads.js')
]
})
export class AdBlockBrowserTestModule { }

const getService = () => TestBed.get(AdBlockService) as AdBlockService
const getHttpMock = () => TestBed.get(HttpTestingController as any) as HttpTestingController

describe(AdBlockBrowserModule.name, () => {
describe(FloAdBlockBrowserModule.name, () => {
afterEach(() => TestBed.resetTestingModule())

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NgModule, ModuleWithProviders } from '@angular/core'
import { HttpClientModule, HttpClient } from '@angular/common/http'
import { AD_BLOCK_PING_URL } from './ad-block.browser.tokens'
import { map, catchError, shareReplay } from 'rxjs/operators'
import { AdBlockModule, AD_BLOCK_LOADER } from '@flosportsinc/ng-ad-block'
import { FloAdBlockModule, AD_BLOCK_LOADER } from '@flosportsinc/ng-ad-block'
import { of } from 'rxjs'

const returnFalse = () => false
Expand All @@ -14,12 +14,12 @@ export function defaultBrowserLoader(http: HttpClient, pingUrl: string) {
}

@NgModule({
imports: [AdBlockModule, HttpClientModule]
imports: [FloAdBlockModule, HttpClientModule]
})
export class AdBlockBrowserModule {
export class FloAdBlockBrowserModule {
static usingUrl(url: string): ModuleWithProviders {
return {
ngModule: AdBlockBrowserModule,
ngModule: FloAdBlockBrowserModule,
providers: [
{
provide: AD_BLOCK_PING_URL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import { AdBlockService } from './ad-block.service'
@NgModule({
providers: [AdBlockService]
})
export class AdBlockModule { }
export class FloAdBlockModule { }
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { TestBed } from '@angular/core/testing'
import { AdBlockModule } from './ad-block.module'
import { FloAdBlockModule } from './ad-block.module'
import { AdBlockService } from './ad-block.service'
import { of } from 'rxjs'
import { AD_BLOCK_LOADER } from './ad-block.tokens'

describe(AdBlockModule.name, () => {
describe(FloAdBlockModule.name, () => {
afterEach(() => TestBed.resetTestingModule())

beforeEach(() => {
TestBed.configureTestingModule({
imports: [AdBlockModule]
imports: [FloAdBlockModule]
})
})

Expand All @@ -19,7 +19,7 @@ describe(AdBlockModule.name, () => {

it('should construct w/ loader', () => {
TestBed.configureTestingModule({
imports: [AdBlockModule],
imports: [FloAdBlockModule],
providers: [
{ provide: AD_BLOCK_LOADER, useValue: of(false) }
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { TestBed } from '@angular/core/testing'
import { AdBlockServerModule } from './ad-block.server.module'
import { FloAdBlockServerModule } from './ad-block.server.module'
import { AdBlockService } from '@flosportsinc/ng-ad-block'

describe(AdBlockServerModule.name, () => {
describe(FloAdBlockServerModule.name, () => {
afterEach(() => TestBed.resetTestingModule())

beforeEach(() => {
TestBed.configureTestingModule({
imports: [AdBlockServerModule]
imports: [FloAdBlockServerModule]
})
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NgModule } from '@angular/core'
import { AdBlockModule, AD_BLOCK_LOADER } from '@flosportsinc/ng-ad-block'
import { FloAdBlockModule, AD_BLOCK_LOADER } from '@flosportsinc/ng-ad-block'
import { shareReplay } from 'rxjs/operators'
import { of } from 'rxjs'

Expand All @@ -8,12 +8,12 @@ export function defaultServerLoader() {
}

@NgModule({
imports: [AdBlockModule],
imports: [FloAdBlockModule],
providers: [
{
provide: AD_BLOCK_LOADER,
useFactory: defaultServerLoader
}
]
})
export class AdBlockServerModule { }
export class FloAdBlockServerModule { }
20 changes: 10 additions & 10 deletions projects/flosportsinc/ng-env-transfer-state/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ Inside your `AppModule` install `NodeEnvTransferModule` like so:

```js
import { NgModule } from '@angular/core'
import { NodeEnvTransferModule } from '@flosportsinc/ng-env-transfer-state'
import { FloNodeEnvTransferModule } from '@flosportsinc/ng-env-transfer-state'

@NgModule({
imports: [
NodeEnvTransferModule
FloNodeEnvTransferModule
]
})
export class AppModule { }
```

Inside your `BrowserModule` install `NodeEnvTransferBrowserModule` like so:
Inside your `BrowserModule` install `FloNodeEnvTransferBrowserModule` like so:

```js
import { NgModule } from '@angular/core'
import { NodeEnvTransferBrowserModule } from '@flosportsinc/ng-env-transfer-state/browser'
import { FloNodeEnvTransferBrowserModule } from '@flosportsinc/ng-env-transfer-state/browser'

@NgModule({
imports: [
NodeEnvTransferBrowserModule, // default behavior simply return the values passed from Node or an empty object if none are found.
NodeEnvTransferBrowserModule.config({ // you can also merge custom values with server values
FloNodeEnvTransferBrowserModule, // default behavior simply return the values passed from Node or an empty object if none are found.
FloNodeEnvTransferBrowserModule.config({ // you can also merge custom values with server values
mergeWithServer: {
MyEnvValue1: true,
MyEnvValue2: 'string',
Expand All @@ -41,16 +41,16 @@ import { NodeEnvTransferBrowserModule } from '@flosportsinc/ng-env-transfer-stat
export class AppBrowserModule { }
```

Inside your `ServerModule` install `NodeEnvTransferServerModule` like so:
Inside your `ServerModule` install `FloNodeEnvTransferServerModule` like so:

```js
import { NgModule } from '@angular/core'
import { NodeEnvTransferServerModule } from '@flosportsinc/ng-env-transfer-state/server'
import { FloNodeEnvTransferServerModule } from '@flosportsinc/ng-env-transfer-state/server'

@NgModule({
imports: [
NodeEnvTransferServerModule, // defaul module passes nothing to the browser
NodeEnvTransferServerModule.config({
FloNodeEnvTransferServerModule, // default module passes nothing to the browser
FloNodeEnvTransferServerModule.config({
selectKeys: [ // pass all variables listed here if they exist (is merged with pattern matched values from extractor property)
'my_awesome_env_variable1',
'my_awesome_env_variable2',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { NodeEnvTransferBrowserModule, INodeEnvTransferBrowserModuleConfig } from './node-env-transfer.browser.module'
import { FloNodeEnvTransferBrowserModule, INodeEnvTransferBrowserModuleConfig } from './node-env-transfer.browser.module'
import { TestBed } from '@angular/core/testing'
import { ENV, ENV_CONFIG_TS_KEY } from '@flosportsinc/ng-env-transfer-state'
import { TransferState } from '@angular/platform-browser'

const setupTestBed = (config?: INodeEnvTransferBrowserModuleConfig) => {
TestBed.configureTestingModule({
imports: [
NodeEnvTransferBrowserModule.config(config)
FloNodeEnvTransferBrowserModule.config(config)
]
})
}

describe(NodeEnvTransferBrowserModule.name, () => {
describe(FloNodeEnvTransferBrowserModule.name, () => {
afterEach(() => TestBed.resetTestingModule())

it('should construct with correct default values', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { NgModule, ModuleWithProviders } from '@angular/core'
import { TransferState, makeStateKey } from '@angular/platform-browser'
import { BrowserTransferStateModule } from '@angular/platform-browser'
import { NodeEnvTransferModule, ENV, ENV_CONFIG_TS_KEY, ENV_CONFIG_DEFAULT, NODE_ENV_USE_VALUES } from '@flosportsinc/ng-env-transfer-state'
import {
FloNodeEnvTransferModule, ENV, ENV_CONFIG_TS_KEY,
ENV_CONFIG_DEFAULT, NODE_ENV_USE_VALUES
} from '@flosportsinc/ng-env-transfer-state'

export function defaultBrowserFactory(ts: TransferState, stateKey: string, merge: Object, sharedMerge: Object) {
return {
Expand All @@ -24,7 +27,7 @@ export const NODE_ENV_CONFIG_DEFAULT = {}
@NgModule({
imports: [
BrowserTransferStateModule,
NodeEnvTransferModule
FloNodeEnvTransferModule
],
providers: [
{
Expand All @@ -38,10 +41,10 @@ export const NODE_ENV_CONFIG_DEFAULT = {}
}
]
})
export class NodeEnvTransferBrowserModule {
export class FloNodeEnvTransferBrowserModule {
static config(config: INodeEnvTransferBrowserModuleConfig = {}): ModuleWithProviders {
return {
ngModule: NodeEnvTransferBrowserModule,
ngModule: FloNodeEnvTransferBrowserModule,
providers: [
{
provide: ENV_CONFIG_DEFAULT,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { TestBed } from '@angular/core/testing'
import { ENV_CONFIG_TS_KEY, NODE_ENV_USE_VALUES } from './node-env-transfer.tokens'
import { NodeEnvTransferModule } from './node-env-transfer.common.module'
import { FloNodeEnvTransferModule } from './node-env-transfer.common.module'

describe(NodeEnvTransferModule.name, () => {
describe(FloNodeEnvTransferModule.name, () => {
afterEach(() => TestBed.resetTestingModule())

beforeEach(() => {
TestBed.configureTestingModule({
imports: [NodeEnvTransferModule]
imports: [FloNodeEnvTransferModule]
})
})

Expand All @@ -19,7 +19,7 @@ describe(NodeEnvTransferModule.name, () => {
it('should construct with config object', () => {
TestBed.resetTestingModule()
TestBed.configureTestingModule({
imports: [NodeEnvTransferModule.config({
imports: [FloNodeEnvTransferModule.config({
useValues: {
test: 'a-ok'
}
Expand All @@ -32,7 +32,7 @@ describe(NodeEnvTransferModule.name, () => {
it('should construct with empty config object', () => {
TestBed.resetTestingModule()
TestBed.configureTestingModule({
imports: [NodeEnvTransferModule.config()]
imports: [FloNodeEnvTransferModule.config()]
})
const sut = TestBed.get(NODE_ENV_USE_VALUES)
expect(sut).toEqual({})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export interface INodeEnvTransferModuleConfig {
}
]
})
export class NodeEnvTransferModule {
export class FloNodeEnvTransferModule {
static config(config: Partial<INodeEnvTransferModuleConfig> = {}): ModuleWithProviders {
return {
ngModule: NodeEnvTransferModule,
ngModule: FloNodeEnvTransferModule,
providers: [
{
provide: NODE_ENV_USE_VALUES,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TestBed } from '@angular/core/testing'
import { NodeEnvTransferService } from './node-env-transfer.service'
import { NodeEnvTransferModule } from './node-env-transfer.common.module'
import { FloNodeEnvTransferModule } from './node-env-transfer.common.module'
import { ENV } from './node-env-transfer.tokens'

interface OurConfig {
Expand All @@ -12,7 +12,7 @@ describe(NodeEnvTransferService.name, () => {

beforeEach(() => {
TestBed.configureTestingModule({
imports: [NodeEnvTransferModule],
imports: [FloNodeEnvTransferModule],
providers: [
{
provide: ENV,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TestBed } from '@angular/core/testing'
import { NODE_ENV, ENV, ENV_CONFIG_SERVER_SELECTED, ENV_CONFIG_SERVER_EXTRACTOR } from '@flosportsinc/ng-env-transfer-state'
import {
NodeEnvTransferServerModule, INodeEnvTransferServerModuleConfig, nodeEnvFactory,
FloNodeEnvTransferServerModule, INodeEnvTransferServerModuleConfig, nodeEnvFactory,
DEFAULT_ENV_CONFIG_EXTRACTOR,
serverEnvConfigFactory,
defaultReplaceExtract,
Expand All @@ -14,8 +14,8 @@ const setupTestBed =
(nodeProcess?: Object) =>
(config?: Partial<INodeEnvTransferServerModuleConfig>) => {
const ServerModule = config
? NodeEnvTransferServerModule.config(config)
: NodeEnvTransferServerModule
? FloNodeEnvTransferServerModule.config(config)
: FloNodeEnvTransferServerModule
TestBed.configureTestingModule({
imports: [ServerModule],
providers: [{
Expand All @@ -25,7 +25,7 @@ const setupTestBed =
})
}

describe(NodeEnvTransferServerModule.name, () => {
describe(FloNodeEnvTransferServerModule.name, () => {
afterEach(() => TestBed.resetTestingModule())

it('should pluck none by default A', () => {
Expand Down Expand Up @@ -64,7 +64,7 @@ describe(NodeEnvTransferServerModule.name, () => {

it('should use defaults when .config is called but not used', () => {
TestBed.configureTestingModule({
imports: [NodeEnvTransferServerModule.config()]
imports: [FloNodeEnvTransferServerModule.config()]
})

expect(TestBed.get(ENV_CONFIG_SERVER_EXTRACTOR)).toEqual(DEFAULT_ENV_CONFIG_EXTRACTOR)
Expand Down
Loading

0 comments on commit d1940a0

Please sign in to comment.