GithubHelp home page GithubHelp logo

zoneless's Introduction

az-zoneless

Known Vulnerabilities build codecov npm version

A set of directive and utilities to manage an angular zoneless app.
Using this library you can go completly zoneless and still support 3rd party libraries like @angular/material.

This library will solve the following:

Warning: This package is experimental

How to work on zoneless mode

Watch this video I made to fully understand the best way to utilize zoneless in your angular app.

Angular going zoneless

Installation

npm i az-zoneless

In your AppModule add the ZonelessModule to the imports array.

import { ZonelessModule } from 'az-zoneless'

@NgModule({
  declarations: [
    ...
  ],
  imports: [
    ...,
    ZonelessModule
  ],
  bootstrap: [AppComponent]
})
export class AppModule {
}

Set your app to be zoneless

This library is meant to be used in an angular running in zoneless mode.
To make angular work without Zone.js please do the following:

  1. from the polyfills.ts comment out the line where Zone.js is imported
// import 'zone.js';  // Included with Angular CLI.
  1. in the main.ts you need to tell angular to not work with Zone.js
platformBrowserDynamic()
  .bootstrapModule(AppModule, {
    ngZone: "noop",
  })
  .catch((err) => console.error(err));

Lecture about using angular in zoneless

Here is a lecture where I explain about angular in zoneless mode

alt

Events

  1. After using the library, make sure to not use the regular events:
<!-- Do not use the regular events   -->
<button (click)="doSomething()"></button>

These events will still work but they are less performent.

  1. To improve performance and really take advantage of the fact that you are zoneless, please use the events like this:
<button (azClick)="doSomething()"></button>
  1. In case you do decide to run angular with Zone.js the library supplies you with an event that will run outside the angular zone.
<!-- the doSomething method will not trigger change detection and will run outside the angular zone -->
<button (azClick.zoneless)="doSomething()"></button>

Directives

If you are afraid to remove zone.js, we also supply with directives that will allow you to incrementally transition your app to be zoneless.
Instead of removing zone.js completly, you can run part of your component tree outside zone.js

azZoneLess

With this directive you can run part of your component tree outside zone.js.
This will work only if you did not remove Zone.js

<div>
  <h1>This part is inside zonejs</h1>
  <button (click)="doSomething()">clicking this will run change detection</button>

  <div *azZoneLess>
    <h1>This part is outside zonejs</h1>
    <button (click)="doSomething()">clicking this will run outside the zone and will only update is you call ChangeDetectorRef.detectChanges()</button>
  </div>
</div>

azZoneFull

If you used the azZoneLess you can go back to running in angular zone using the azZoneFull directive. This directive will only work if you did not remove Zone.js.

<div>
  <h1>This part is inside zonejs</h1>
  <button (click)="doSomething()">clicking this will run change detection</button>

  <div *azZoneLess>
    <h1>This part is outside zonejs</h1>
    <button (click)="doSomething()">clicking this will run outside the zone and will only update is you call ChangeDetectorRef.detectChanges()</button>

    <div *azZoneFull>
      <!-- This will return us back to the zone.js -->
      <button (click)="doSomething()">This runs in the zone.js</button>
    </div>
  </div>
</div>

zoneless's People

Contributors

ywarezk avatar

Stargazers

 avatar Deuri Vasquez avatar  avatar Tomas Rimkus avatar Vladimir Drayling avatar Michael Scharf avatar hxj avatar Mohamad Reza Golab avatar  avatar  avatar Pierre-Edouard Galtier avatar Marko Stanimirović avatar Toni Villena avatar

Watchers

Belan avatar  avatar  avatar

Forkers

georgepu

zoneless's Issues

browser's autofill disappear

In the example app (source code) the image below demonstrates the autofilled auth form:
image

After clicking somewhere values disappear
image
but in a zone-full app they don't.

How to solve this issue? Values should stay autofilled in the form.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.