npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cerebral/angular

v5.0.0

Published

Angular view for Cerebral

Readme

@cerebral/angular

Angular integration for Cerebral state management.

Installation

npm install @cerebral/angular @angular/core @angular/platform-browser

Usage

AppService

AppService is the core service that creates and exposes the Cerebral controller to your Angular application.

Setup in Angular App

// app.config.ts
import { ApplicationConfig } from '@angular/core'
import { provideAnimations } from '@angular/platform-browser/animations'
import { provideRouter } from '@angular/router'
import { AppService } from '@cerebral/angular'
import { SomeService } from './some.service'
import { routes } from './app.routes'

// Create a Cerebral app factory
export function createCerebralApp(someService: SomeService) {
  return new AppService({
    state: {
      count: 0,
      items: []
    },
    sequences: {
      increment: [
        ({ store, get }) => store.set('count', get(state`count`) + 1)
      ],
      decrement: [({ store, get }) => store.set('count', get(state`count`) - 1)]
    },
    providers: {
      // Provide Angular services to Cerebral
      someService
    }
  })
}

// Provide AppService in your app config
export const appConfig: ApplicationConfig = {
  providers: [
    provideRouter(routes),
    provideAnimations(),
    {
      provide: AppService,
      useFactory: createCerebralApp,
      deps: [SomeService]
    }
  ]
}

Components

Using the connect decorator

The connect decorator connects Cerebral state and sequences to your components:

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

@Component({
  selector: 'app-counter',
  standalone: true, // In Angular 19+ is this the default
  template: `
    <div>
      <h2>Count: {{ count }}</h2>
      <button (click)="increment()">+</button>
      <button (click)="decrement()">-</button>
    </div>
  `,
  // OnPush change detection is required for optimal performance
  changeDetection: ChangeDetectionStrategy.OnPush
})
@connect({
  count: state`count`,
  increment: sequences`increment`,
  decrement: sequences`decrement`
})
export class CounterComponent extends CerebralComponent {
  // Properly declare connected properties with TypeScript
  count!: number
  increment!: () => void
  decrement!: () => void

  constructor(
    @Inject(ChangeDetectorRef) cdr: ChangeDetectorRef,
    @Inject(AppService) app: AppService
  ) {
    super(cdr, app)
  }
}

Working with Parent/Child Components

For parent-child component relationships, ensure child components are properly imported:

import {
  Component,
  ChangeDetectionStrategy,
  ChangeDetectorRef,
  Inject
} from '@angular/core'
import { state, sequences } from 'cerebral'
import { connect, AppService, CerebralComponent } from '@cerebral/angular'
import { ChildComponent } from './child.component'

@Component({
  selector: 'app-parent',
  standalone: true,
  imports: [ChildComponent],
  template: `
    <div>
      <h1>Parent</h1>
      <app-child [data]="items"></app-child>
      <button (click)="addItem()">Add Item</button>
    </div>
  `,
  // Change detection needs to be set to OnPush
  changeDetection: ChangeDetectionStrategy.OnPush
})
@connect({
  items: state`items`,
  addItem: sequences`addItem`
})
export class ParentComponent extends CerebralComponent {
  items!: any[]
  addItem!: () => void

  constructor(
    @Inject(ChangeDetectorRef) cdr: ChangeDetectorRef,
    @Inject(AppService) app: AppService
  ) {
    super(cdr, app)
  }
}

Advanced Features

Using Angular Services in Cerebral Sequences

You can inject Angular services into your Cerebral sequences using providers:

// app.config.ts
import { HttpClient } from '@angular/common/http'
import { ApplicationConfig } from '@angular/core'
import { AppService } from '@cerebral/angular'

export function createCerebralApp(httpClient: HttpClient) {
  return new AppService({
    state: {
      data: null,
      loading: false,
      error: null
    },
    sequences: {
      fetchData: [
        ({ store }) => store.set('loading', true),
        async ({ http }) => {
          try {
            const response = await http.get('/api/data').toPromise()
            return { response }
          } catch (error) {
            return { error }
          }
        },
        ({ store, props }) => {
          if (props.error) {
            store.set('error', props.error)
          } else {
            store.set('data', props.response)
          }
          store.set('loading', false)
        }
      ]
    },
    providers: {
      http: httpClient
    }
  })
}

export const appConfig: ApplicationConfig = {
  providers: [
    {
      provide: AppService,
      useFactory: createCerebralApp,
      deps: [HttpClient]
    }
  ]
}

Using Computed Values

Cerebral uses functions to compute derived state values:

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

// 1. Define types for better type safety
type Item = { id: number; name: string }
type AppState = {
  items: Item[]
  filter: string
  filteredItems?: Item[]
}

// 2. Define the computed function
const filteredItems = (get: any) => {
  const items = get(state`items`)
  const filter = get(state`filter`)
  return items.filter((item: Item) =>
    filter ? item.name.includes(filter) : true
  )
}

// 3. Create your app with computed properties
const app = new AppService({
  state: {
    items: [],
    filter: '',
    filteredItems // Attach computed to state
  } as AppState,
  sequences: {
    // Define your sequences here
  }
})

// 4. Use in component
@Component({
  standalone: true
  // ...component config
})
@connect({
  filteredItems: state`filteredItems` // Access via state tag or proxy
})
export class ListComponent extends CerebralComponent {
  // Declare with proper type
  filteredItems!: Item[]
}

Computed values automatically track their dependencies and only recalculate when necessary, improving performance for derived state.

Troubleshooting

Common Issues

  1. State updates not reflected in components

    • Make sure your component uses ChangeDetectionStrategy.OnPush
    • Check that you've extended CerebralComponent
    • Verify you're using @Inject() for dependency injection
  2. TypeScript errors with connected properties

    • Always declare connected properties with the correct type and ! assertion
    • Example: count!: number;
  3. Angular directives not working

    • When using standalone components, remember to import needed directives
    • Example: imports: [NgIf, NgFor, CommonModule]
  4. Component not updating after state change

    • Check if you need to call app.flush() after sequence execution in tests
    • In components, sequences are automatically flushed