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

@cerebral/angular

Package Overview
Dependencies
Maintainers
6
Versions
266
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cerebral/angular

Angular view for Cerebral

  • 4.2.1-1577723604565
  • Source
  • npm
  • Socket score

Version published
Maintainers
6
Created
Source

@cerebral/angular

Angular view for Cerebral.

Install

npm install @cerebral/angular @angular/core @angular/platform-browser babel-plugin-transform-decorators-legacy

CerebralService

The Cerebral service exposes the Cerebral controller to your application.

import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'

import { provide } from 'cerebral'
import { AppService } from '@cerebral/angular'

import { AppComponent }  from './app.component.ts'
import { SomeAngularService } from './SomeAngularService'

// Create a factory to instantiate Cerebral. It can receive
// dependencies which you can "provide" to Cerebral to be used
// within sequences
export function configureApp(someAngularService : SomeAngularService) {
  return new AppService({
    // We use the "provide" function to an angular service to the sequences
    // of Cerebral
    providers: [
      provide('someAngularService', someAngularService)
    ]
  })
})

@NgModule({
  imports:      [ BrowserModule ],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ],
  providers: [
     {
      provide: AppService,
      useFactory: configureApp,
      deps: [SomeAngularService]
    },
  ]
})
export class AppModule {}

connect decorator

The connect decorator connects state and signals to your components.

import {
  Component,
  ChangeDetectionStrategy,
  ChangeDetectorRef
} from '@angular/core'
import { sequences, state } from 'cerebral/tags'
import {
  connect,
  AppService,
  CerebralComponent
} from '@cerebral/angular'

@Component({
  selector: 'app-component',
  template: `
    <div (click)="onClick()">{{foo}}</div>
  `,
  // Change detection needs to be set to "OnPush"
  changeDetection: ChangeDetectionStrategy.OnPush
})
@connect({
  // For AOT to work you will have to use the array version of template
  // tags
  myName: state(['foo']),
  onClick: sequences(['clicked'])
})
export class AppComponent extends CerebralComponent {
  // You have to inject "ChangeDetectionRef" and "ControllerService" and pass
  // them to parent for connect to do its work
  constructor(cdr: ChangeDetectorRef, app: AppService) {
    super(cdr, app)
    app.getSequence('onClick')()
  }
}

FAQs

Package last updated on 30 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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