Skip to content

Instantly share code, notes, and snippets.

@oleksii-shepel
oleksii-shepel / rxjs-operators-patch.ts
Last active May 8, 2024 15:09
patch for rxjs operators that by calling returns method with a name property
import * as operators from 'rxjs/operators';
export default function patchOperators(useOriginals = false) {
if (useOriginals === false) {
return new Proxy(operators, {
get: function(target, prop) {
const original = (target as any)[prop];
if (typeof original === 'function') {
return function(...args: any[]) {
const result = original(...args);
@oleksii-shepel
oleksii-shepel / store_module_for_feature.ts
Created March 15, 2024 09:28
store module for feature
import { CommonModule } from "@angular/common";
import { NgModule } from "@angular/core";
import { FormsModule } from "@angular/forms";
import { RouterModule, Routes } from "@angular/router";
import { StoreModule } from "actionstack";
import { HeroService } from '../hero.service';
import { HeroDetailsComponent } from './hero-details.component';
import { reducer, slice } from "./hero-details.slice";
const routes: Routes = [
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { Action, StoreModule, measure } from 'actionstack';
import { AppRoutingModule } from './app-routing.module';
import { MessagesModule } from './messages/messages.module';
@NgModule({
imports: [
@oleksii-shepel
oleksii-shepel / slice.ts
Created March 15, 2024 09:25
slice usage
import { CommonModule } from '@angular/common';
import { Component, OnInit } from '@angular/core';
import { RouterModule } from '@angular/router';
import { Slice } from 'actionstack';
import { Observable } from 'rxjs';
import { Hero } from '../hero';
import { HeroService } from './../hero.service';
import { loadHeroes, reducer, selectTopHeroes, slice } from './dashboard.slice';
@Component({
import { Action, action } from "actionstack";
import { map } from "rxjs";
import { Hero } from "../hero";
export const slice = "heroes";
export const getHeroesRequest = action("GET_HEROES_REQUEST", (heroes: Hero[]) => ({heroes}));
export const getHeroesSuccess = action("GET_HEROES_SUCCESS", (heroes: Hero[]) => ({heroes}));
export const loadHeroes = (action$, state$, { heroService }: any) => {
import { Action, action } from "actionstack";
import { firstValueFrom } from "rxjs";
import { Hero } from "../hero";
export const slice = "hero-details";
export const loadHeroRequest = action('LOAD_HERO_REQUEST');
export const loadHeroSuccess = action('LOAD_HERO_SUCCESS', (hero: Hero) => ({ hero }));
export const loadHeroFailure = action('LOAD_HERO_FAILURE', (error: Error) => ({ error }));
import { featureSelector, selector } from "actionstack";
export const slice = "messages";
export const feature = featureSelector(slice);
export const selectMessages = selector(feature, state => state.messages);
export const selectMessageCount = selector(feature, state => state.messages.length);
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Store } from 'actionstack';
import { Subscription } from 'rxjs';
import { Hero } from '../hero';
import { selectHeroes } from './heroes.slice';
@Component({
selector: 'app-heroes',
templateUrl: './heroes.component.html',
@oleksii-shepel
oleksii-shepel / action_dispatching.ts
Created March 12, 2024 16:01
action dispatching
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Store } from 'actionstack';
import { getHeroesRequest } from './heroes.slice';
@Component({
selector: 'app-heroes',
templateUrl: './heroes.component.html',
styleUrls: ['./heroes.component.css']
})
export class HeroesComponent implements OnInit, OnDestroy {
@oleksii-shepel
oleksii-shepel / create_store.ts
Last active March 13, 2024 14:44
create store
import { Action, store, measure } from 'actionstack';
const storeInstance = store({
middlewares: [measure],
reducer: (state: any = {}, action: Action<any>) => state,
dependencies: {},
strategy: "concurrent",
});