Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

angular-breakpoints

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-breakpoints - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

19

index.js

@@ -38,2 +38,3 @@ "use strict";

this.ngZone = ngZone;
this.lastBreakpoint = null;
this.breakpoints = defaultBreakpoints;

@@ -60,13 +61,15 @@ this.setBreakpoints(breakpoints);

}
this.subscription = this.resize.subscribe(function (size) {
var breakpoint = _this.getBreakpoint(size.width);
if (core_1.NgZone.isInAngularZone()) {
_this.changesSubject.next(_this.getBreakpointEvent(breakpoint));
}
else {
// NgZone doesnt listen to resize window event, so we have to run this in NgZone to run change detection
// Make sure resize event doesn't trigger change detection by running outside of angular zone
this.ngZone.runOutsideAngular(function () {
_this.subscription = _this.resize.subscribe(function (size) {
var breakpoint = _this.getBreakpoint(size.width);
if (breakpoint === _this.lastBreakpoint) {
return;
}
_this.lastBreakpoint = breakpoint;
// Emitting back in angular zone
_this.ngZone.run(function () {
_this.changesSubject.next(_this.getBreakpointEvent(breakpoint));
});
}
});
});

@@ -73,0 +76,0 @@ };

@@ -57,2 +57,3 @@ import { Injectable, provide, NgZone } from '@angular/core';

private lastBreakpoint: string = null;
private breakpoints: BreakpointConfig = defaultBreakpoints;

@@ -93,16 +94,22 @@ private changesSubject: BehaviorSubject<BreakpointEvent>;

this.subscription = this.resize.subscribe((size: WindowSize) => {
// Make sure resize event doesn't trigger change detection by running outside of angular zone
this.ngZone.runOutsideAngular(() => {
const breakpoint: string = this.getBreakpoint(size.width);
if (NgZone.isInAngularZone()) {
this.changesSubject.next(this.getBreakpointEvent(breakpoint));
}
else {
// NgZone doesnt listen to resize window event, so we have to run this in NgZone to run change detection
this.subscription = this.resize.subscribe((size: WindowSize) => {
const breakpoint: string = this.getBreakpoint(size.width);
if (breakpoint === this.lastBreakpoint) {
return;
}
this.lastBreakpoint = breakpoint;
// Emitting back in angular zone
this.ngZone.run(() => {
this.changesSubject.next(this.getBreakpointEvent(breakpoint));
});
}
});
});
}

@@ -109,0 +116,0 @@

{
"name": "angular-breakpoints",
"version": "1.0.2",
"version": "1.1.0",
"description": "Angular 2 service to programmatically listen to breakpoints",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -99,2 +99,5 @@ [![NPM Version](https://img.shields.io/npm/v/angular-breakpoints.svg)](https://npmjs.com/package/angular-breakpoints)

If you want to temporarily unsubscribe to the resize event, just call the `unsubscribe` method.
If you want to resubscribe, call the `subscribe` method.
If you want to resubscribe, call the `subscribe` method.
The methods exist but the resize event does not run in `NgZone` so it will not trigger change detection.
Thus, the performance should not be affected.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc