Skip to content

Commit 6c0264a

Browse files
committed
feat(InViewport): Updating WindowRef service with more mock properties and functions
Add common window functions and properties to help when running on server platform. Also created a new injection token to inject browser window object or WindowRef instance BREAKING CHANGE: inViewportModule.forRoot function now only accepts a single argument which should be a reference to window or a mock window implementation
1 parent 63f3d6e commit 6c0264a

File tree

13 files changed

+237
-108
lines changed

13 files changed

+237
-108
lines changed

.angular-cli.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@
5353
"config": "./karma.conf.js"
5454
},
5555
"codeCoverage": {
56-
"exclude": ["./src/app/testing/*.ts"]
56+
"exclude": [
57+
"./src/app/testing/*.ts",
58+
"./src/app/in-viewport/window/window.service.ts"
59+
]
5760
}
5861
},
5962
"defaults": {

README.md

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,51 @@
44

55
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 1.5.4.
66

7-
A simple lightweight library for [Angular (2+)][angular] with no other dependencies that detects when an element is within the browser viewport and adds a `sn-viewport-in` or `sn-viewport-out` class to the element.
7+
A simple lightweight library for [Angular (2/4/5+)][angular] with no other dependencies that detects when an element is within the browser viewport and adds a `sn-viewport-in` or `sn-viewport-out` class to the element.
88

9-
This is a simple library for [Angular][angular], implemented in the [Angular Package Format v4.0](https://docs.google.com/document/d/1CZC2rcpxffTDfRDs6p1cfbmKNLA6x5O-NtkJglDaBVs/edit#heading=h.k0mh3o8u5hx).
9+
This is a simple library for [Angular][angular], implemented in the [Angular Package Format v5.0](https://docs.google.com/document/d/1CZC2rcpxffTDfRDs6p1cfbmKNLA6x5O-NtkJglDaBVs/edit#heading=h.k0mh3o8u5hx).
1010

1111

1212
## Install
1313

14-
`npm i @thisissoon/angular-inviewport --save`
14+
### npm
15+
16+
```
17+
npm i @thisissoon/angular-inviewport --save
18+
```
19+
### yarn
20+
21+
```
22+
yarn add @thisissoon/angular-inviewport
23+
```
1524

1625
`app.module.ts`
1726
```ts
18-
import { InViewportModule, WindowRef } from '@thisissoon/angular-inviewport';
19-
20-
// Provide window object so as to not break SSR if using universal
21-
export const getWindow = () => window;
22-
export const providers: Provider[] = [
23-
{ provide: WindowRef, useFactory: (getWindow) }
24-
];
27+
import { InViewportModule } from '@thisissoon/angular-inviewport';
2528

2629
@NgModule({
2730
imports: [
28-
InViewportModule.forRoot(providers)
31+
// pass window object to forRoot function
32+
InViewportModule.forRoot(window)
2933
]
3034
})
3135
export class AppModule { }
3236
```
3337

38+
`app.server.module.ts`
39+
```ts
40+
import { InViewportModule } from '@thisissoon/angular-inviewport';
41+
42+
@NgModule({
43+
imports: [
44+
// no need to pass any arguments to forRoot
45+
// function for server module
46+
InViewportModule.forRoot()
47+
]
48+
})
49+
export class AppServerModule { }
50+
```
51+
3452

3553
## Examples
3654

index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export {
66
} from './src/app/in-viewport/shared/event-data';
77
export { Viewport } from './src/app/in-viewport/shared/viewport.model';
88
export { WindowRef } from './src/app/in-viewport/window/window.service';
9+
export { WINDOW } from './src/app/in-viewport/window/window-token';

karma.conf.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ module.exports = function (config) {
3030
colors: true,
3131
logLevel: config.LOG_INFO,
3232
autoWatch: true,
33-
browsers: ['Chrome'],
33+
customLaunchers: {
34+
ChromeNoSandbox: {
35+
base: 'Chrome',
36+
flags: ['--no-sandbox']
37+
}
38+
},
39+
browsers: ['ChromeNoSandbox'],
3440
singleRun: false
3541
});
3642
};

package-lock.json

Lines changed: 96 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"angular",
77
"angular 2",
88
"angular 4",
9+
"angular 5",
910
"directive",
1011
"viewport",
1112
"in viewport",
@@ -60,6 +61,7 @@
6061
"codelyzer": "^4.0.1",
6162
"core-js": "^2.4.1",
6263
"coveralls": "^3.0.0",
64+
"cz-conventional-changelog": "^2.1.0",
6365
"jasmine-core": "~2.6.2",
6466
"jasmine-spec-reporter": "~4.1.0",
6567
"karma": "~1.7.0",
@@ -72,10 +74,15 @@
7274
"ng-packagr": "^2.0.0-rc.4",
7375
"protractor": "~5.1.2",
7476
"rxjs": "^5.5.2",
75-
"standard-version": "^4.2.0",
77+
"standard-version": "^4.3.0",
7678
"ts-node": "~3.2.0",
7779
"tslint": "~5.7.0",
7880
"typescript": "~2.4.2",
7981
"zone.js": "^0.8.14"
82+
},
83+
"config": {
84+
"commitizen": {
85+
"path": "./node_modules/cz-conventional-changelog"
86+
}
8087
}
8188
}

0 commit comments

Comments
 (0)