GithubHelp home page GithubHelp logo

briebug / smartish Goto Github PK

View Code? Open in Web Editor NEW
2.0 22.0 1.0 416 KB

Smartish is a small utility library that makes creating "smartish" components in Angular a breeze

TypeScript 82.18% JavaScript 3.23% HTML 13.00% SCSS 1.57% Shell 0.02%
angular typescript ngrx state-management state state-pattern state-machine components component-architecture

smartish's Introduction

NgRx Smartish

NgRx Smartish is a small utility library that makes creating "smartish" components in Angular a breeze. NgRx mixed with Smartish Components, provide a clean and declartive approach to building applications in Angular.

Getting Started

You can install the package using npm install @briebug/ngrx-smartish

Next you will need to import NgRxSmartishModule in app.module as well as provide store using the SMARTISH_STORE_TOKEN.

import { NgRxSmartishModule, SMARTISH_STORE_TOKEN } from '@briebug/ngrx-smartish';
imoprt { StoreModule, Store } from '@ngrx/store';

@NgModule({
  imports: [
      NgRxSmartishModule,
      StoreModule.forRoot({...})
  ],
  providers: [{ provide: SMARTISH_STORE_TOKEN, useClass: Store }]
})
export class AppModule {}

SmartSelect

With SmartishNgRx you can reference NgRx Selectors directly in your Angular Component's template without the need to inject the store. You simple need to add the MemoizedSelector in your component class and reference that property with the smartSelector pipe in your template.

import { selectError } from 'YOUR-STORE'

@Component({
    selector: 'app-error',
    template: `<p>{{ selectError | smartSelect | async }}</p>`
})
export class ErrorComponent {
    error = selectError;
}

SmartDispatch

With SmartishNgRx you can dispatch actions directly in your Angular Component's template without the need to dispatch an @Output() EventEmitter or injecting the store. You simply can use either the smartDispatch method.

import { smartDispatch } from '@briebug/ngrx-smartish';
import { addTaco } from '...my-actions';

@Component({
    selector: 'app-component',
    template: `<button (click)="addTaco({ taco: form.value })">Add Taco</button>
})
export class MyComponent {
    addTaco = smartDispatch(addTaco);
}

NgRxSmartishComponent

With SmartishNgRx you can reference your NgRx store directly in your Components classes (or templates) without providing the store in the constructor. It's as easy as having your component extends SmartishNgRxComponent.

@Component({
    selector: 'app-tacos',
    template: `<app-taco *ngFor="let taco of (tacos$ | async)" [taco]="taco></app-taco>`
})
export class TacosComponent extends SmartishNgRxComponent {
    tacos$ = store.select(selectTacos);
}

Testing

Testing with NgRxSmartish is made simple with the NgRxSmartishTestingModule. Just import NgRxSmartishTestingModule into your TestBed with the forRoot() static method. You can also pass an optional MockStoreConfig inside of forRoot() to save you from having to provide provideMockStore(...) in your tests.

const config = { };
describe('YourSmartishComponent', () => {
  beforeEach(async () => {
    imports: [NgRxSmartishTestingModule.forRoot({ initialState: {...}})],
    declarations: [YourSmartishComponent]
  });
});

smartish's People

Contributors

jordanpowell88 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

jordanpowell88

smartish's Issues

test: Add Real World Store App to Workspace

We need a better application to verify smartish is working with real-life enterprise applications. It will give us a great example for demos and be a great resource to provide e2e tests and do smoke testing moving forward. It should include the following:

  • Lazy Loaded Modules
  • Cypress Tests
  • Using Smartish

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.