ProductPromotion
Logo

Angular.JS

made by https://0x3d.site

GitHub - politie/ngx-sherlock: ngx-sherlock is an Angular tooling library to be used with the @politie/sherlock distributed reactive state management library.
ngx-sherlock is an Angular tooling library to be used with the @politie/sherlock distributed reactive state management library. - politie/ngx-sherlock
Visit Site

GitHub - politie/ngx-sherlock: ngx-sherlock is an Angular tooling library to be used with the @politie/sherlock distributed reactive state management library.

GitHub - politie/ngx-sherlock: ngx-sherlock is an Angular tooling library to be used with the @politie/sherlock distributed reactive state management library.

Ngx Sherlock

CI Known Vulnerabilities npm version license

NgxSherlock is a set of Angular bindings for the Sherlock reactive state management library.

Usage

Installation

Install NgxSherlock by running:

npm install @politie/ngx-sherlock

Add the NgxSherlockModule to your AppModule:

import { NgModule } from '@angular/core';
import { NgxSherlockModule } from '@politie/ngx-sherlock';

@NgModule({
    imports: [NgxSherlockModule],
    ...
})
export class AppModule { }

autoDetectChanges

Signature:

class AutoChangeDetectorService {
    init(): Promise<void>;
}

The AutoChangeDetectorService enables automatic change detection when using Sherlock Derivables, even when using the OnPush change-detection-strategy. The alternative is to use the value-pipe which is explained below. When using the AutoChangeDetectorService it is no longer needed to use the pipe.

The service needs to be instantiated once for each component. This is accomplished by mentioning it in the providers section of the Component metadata. It will detach the default ChangeDetector and re-enables change detection once #init() is called. This will ensure that change detection is wrapped with Sherlock magic.

The AutoChangeDetectorService service guarantees model and view fidelity, meaning one can easily use Angular's forms and template functionality.

Example

trusty-sidekick.component.ts:

import { Component, ChangeDetectionStrategy, ChangeDetectorRef, Input } from '@angular/core';
import { AutoChangeDetectorService } from '@politie/ngx-sherlock';
import { atom, Derivable } from '@politie/sherlock';

@Component({
    selector: 'trusty-sidekick',
    template: `
        <input type="text" [(ngModel)]="firstname$.value" placeholder="First name">
        <input type="text" [(ngModel)]="surname$.value" placeholder="Surname">
        <sidekick-greeter [name]="sidekick$"></sidekick-greeter>
    `,
    providers: [AutoChangeDetectorService],
})
export class TrustySidekickComponent {
    readonly sidekick$ = atom({ firstname: 'John', surname: 'Watson' });
    readonly firstname$ = this.sidekick$.pluck('firstname');
    readonly surname$ = this.sidekick$.pluck('surname');

    // Here we call AutoChangeDetectorService#init which will automatically react on changes in the state of
    // any used derivable.
    constructor(autoCD: AutoChangeDetectorService) { autoCD.init(); }
}

@Component({
    selector: 'sidekick-greeter',
    template: `
        <h2 *ngIf="!beObnoxious">Well hello there, {{ name.value.firstname }} {{ name.value.surname }}!</h2>
        <h2 *ngIf="beObnoxious">So good of you to finally join us, {{ name.value.surname }}...</h2>
        
        <button (click)="toggle()">Change mood</button>     
    `,
    changeDetection: ChangeDetectionStrategy.OnPush,
    providers: [AutoChangeDetectorService],
})
export class SidekickGreeterComponent implements OnInit {
    @Input() name: Derivable<{ firstname: string, surname: string }>;
    obnoxious$ = atom(false);

    get beObnoxious() {
        return this.obnoxious$.get();
    }

    constructor(autoCD: AutoChangeDetectorService) { autoCD.init(); }

    toggle() {
        this.obnoxious$.swap(mood => !mood);
    }
}

ValuePipe

The ValuePipe unwraps a Derivable or DerivableProxy value and triggers the ChangeDetectorRef whenever an internal value changes and a change detection cycle is needed. This allows a component to have an OnPush ChangeDetectionStrategy, greatly increasing performance.

Example

my.component.html:

<h1>My awesome counter</h1>
<p>We're already at: <strong>{{ counter$ | value }}</strong></p>

my.component.ts:

import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
import { atom } from '@politie/sherlock';

@Component({
    selector: 'my-component';
    templateUrl: 'my.component.html',
    changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MyComponent implements OnInit {
    readonly counter$ = atom(0);

    ngOnInit() {
        setInterval(() => this.counter$.swap(i => i++), 1000);
    }
}

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory