Skip to content

Commit

Permalink
feat(store): add standalone features (#1999)
Browse files Browse the repository at this point in the history
  • Loading branch information
arturovt authored Aug 27, 2023
1 parent b2e9283 commit d522732
Show file tree
Hide file tree
Showing 62 changed files with 952 additions and 429 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# - ./.github/actions/download-integration-test-artifacts

name: download-integration-test-artifact
description: Downloads all integration test artifacts with names such as 'hello-world-ng15-ivy'.
description: Downloads all integration test artifacts with names such as 'hello-world-ng15'.

inputs:
path:
Expand All @@ -18,8 +18,8 @@ inputs:
runs:
using: 'composite'
steps:
- name: Download hello-world-ng15-ivy artifacts
- name: Download hello-world-ng15 artifacts
uses: actions/download-artifact@v3
with:
name: hello-world-ng15-ivy
name: hello-world-ng15
path: ${{ inputs.path }}
6 changes: 3 additions & 3 deletions .github/actions/upload-integration-test-artifact/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
# - ./.github/actions/upload-integration-test-artifact

name: upload-integration-test-artifact
description: Upload an integration test artifact with a name such as 'hello-world-ng15-ivy'.
description: Upload an integration test artifact with a name such as 'hello-world-ng15'.

inputs:
script:
description: A script with a name such as 'integration:ng15:ivy' that generates an integration test artifact.
description: A script with a name such as 'integration:ng15' that generates an integration test artifact.
required: true

runs:
Expand All @@ -21,7 +21,7 @@ runs:
id: artifact-name
shell: bash
run: |
echo "Replace colons with dashes, substring 'integration' with a substring 'hello-world'. Example result: hello-world-ng12-ivy"
echo "Replace colons with dashes, substring 'integration' with a substring 'hello-world'. Example result: hello-world-ng15"
echo "value=$(echo ${SCRIPT} | sed -r "s/:/-/g" | sed -r "s/integration/hello-world/g")" >> $GITHUB_OUTPUT
env:
SCRIPT: ${{ inputs.script }}
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/pr-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ jobs:
strategy:
matrix:
script:
# - 'integration:ng12:ivy'
# - 'integration:ng13:ivy'
# - 'integration:ng14:ivy'
- 'integration:ng15'
- 'integration:ng16'
- 'test:types'
Expand All @@ -108,7 +105,7 @@ jobs:
run: yarn ${{ matrix.script }}

- name: Upload an integration test artifact
if: ${{ matrix.script == 'integration:ng12:ivy' || matrix.script == 'integration:ng13:ivy' || matrix.script == 'integration:ng14:ivy' }}
if: ${{ matrix.script == 'integration:ng15' }}
uses: ./.github/actions/upload-integration-test-artifact
with:
script: ${{ matrix.script }}
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/trunk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ jobs:
strategy:
matrix:
script:
# - 'integration:ng12:ivy'
# - 'integration:ng13:ivy'
# - 'integration:ng14:ivy'
- 'integration:ng15'
- 'test:types'

steps:
Expand All @@ -98,7 +96,7 @@ jobs:
run: yarn ${{ matrix.script }}

- name: Upload an integration test artifact
if: ${{ matrix.script == 'integration:ng12:ivy' || matrix.script == 'integration:ng13:ivy' || matrix.script == 'integration:ng14:ivy' }}
if: ${{ matrix.script == 'integration:ng15' }}
uses: ./.github/actions/upload-integration-test-artifact
with:
script: ${{ matrix.script }}
Expand Down
9 changes: 9 additions & 0 deletions integration/app/app-browser.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ApplicationConfig } from '@angular/platform-browser';
import { provideAnimations } from '@angular/platform-browser/animations';

import { appConfig } from './app.config';

// TODO: use `mergeApplicationConfig` in v16.
export const appBrowserConfig: ApplicationConfig = {
providers: [provideAnimations(), ...appConfig.providers]
};
26 changes: 0 additions & 26 deletions integration/app/app-routing.module.ts

This file was deleted.

9 changes: 9 additions & 0 deletions integration/app/app-server.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ApplicationConfig } from '@angular/platform-browser';
import { provideNoopAnimations } from '@angular/platform-browser/animations';

import { appConfig } from './app.config';

// TODO: use `mergeApplicationConfig` in v16.
export const appServerConfig: ApplicationConfig = {
providers: [provideNoopAnimations(), ...appConfig.providers]
};
19 changes: 0 additions & 19 deletions integration/app/app.browser.module.ts

This file was deleted.

31 changes: 18 additions & 13 deletions integration/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { TestBed, ComponentFixture, fakeAsync, tick } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { ComponentFixtureAutoDetect, discardPeriodicTasks } from '@angular/core/testing';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { take } from 'rxjs/operators';
import { Store } from '@ngxs/store';
import { Store, provideStore } from '@ngxs/store';
import { withNgxsFormPlugin } from '@ngxs/form-plugin';

import { AppComponent } from '@integration/app.component';
import { AppModule } from '@integration/app.module';
import { Pizza, Todo } from '@integration/store/todos/todos.model';
import { AppComponent } from './app.component';
import { Pizza, Todo } from './store/todos/todos.model';
import { TodosState } from './store/todos/todos.state';
import { TodoState } from './store/todos/todo/todo.state';

describe('AppComponent', () => {
let fixture: ComponentFixture<AppComponent>;
Expand All @@ -22,8 +22,8 @@ describe('AppComponent', () => {

beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppModule, RouterTestingModule, FormsModule, ReactiveFormsModule],
providers: [{ provide: ComponentFixtureAutoDetect, useValue: true }]
imports: [RouterTestingModule],
providers: [provideStore([TodosState, TodoState], withNgxsFormPlugin())]
});

fixture = TestBed.createComponent(AppComponent);
Expand Down Expand Up @@ -54,7 +54,10 @@ describe('AppComponent', () => {
});
});

it('should set toppings using form control', fakeAsync(() => {
it('should set toppings using form control', fakeAsync(async () => {
fixture.detectChanges();
await fixture.whenStable();

component.pizzaForm.patchValue({ toppings: 'oli' });
tick(200);
let flag = false;
Expand All @@ -80,12 +83,15 @@ describe('AppComponent', () => {
expect(flag).toBe(true);
}));

it('should set toppings prefix', fakeAsync(() => {
it('should set toppings prefix', fakeAsync(async () => {
fixture.detectChanges();
await fixture.whenStable();

component.pizzaForm.patchValue({ toppings: 'cheese' });
tick(200);
tick(100);
component.onPrefix();
let flag = false;
tick(200);
tick(100);

component.pizza$.pipe(take(1)).subscribe((pizza: Pizza) => {
flag = true;
Expand All @@ -95,7 +101,6 @@ describe('AppComponent', () => {
});

expect(flag).toBe(true);
discardPeriodicTasks();
}));

it('should load data in pizza form', () => {
Expand Down
18 changes: 15 additions & 3 deletions integration/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { FormArray, FormBuilder, FormControl } from '@angular/forms';
import { Component, OnInit } from '@angular/core';
import {
FormArray,
FormBuilder,
FormControl,
FormsModule,
ReactiveFormsModule
} from '@angular/forms';
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
import { Store } from '@ngxs/store';
import { NgxsFormDirective } from '@ngxs/form-plugin';
import { Observable } from 'rxjs';

import { TodoState } from '@integration/store/todos/todo/todo.state';
Expand All @@ -11,7 +20,10 @@ import { Extras, Pizza, Todo } from '@integration/store/todos/todos.model';

@Component({
selector: 'app-root',
templateUrl: './app.component.html'
templateUrl: './app.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [CommonModule, RouterModule, FormsModule, ReactiveFormsModule, NgxsFormDirective]
})
export class AppComponent implements OnInit {
readonly allExtras: Extras[] = [
Expand Down
51 changes: 51 additions & 0 deletions integration/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { APP_ID } from '@angular/core';
import { provideRouter } from '@angular/router';
import { ApplicationConfig } from '@angular/platform-browser';
import { provideStore } from '@ngxs/store';
import { withNgxsFormPlugin } from '@ngxs/form-plugin';
import { withNgxsLoggerPlugin } from '@ngxs/logger-plugin';
import { withNgxsReduxDevtoolsPlugin } from '@ngxs/devtools-plugin';
import { withNgxsRouterPlugin } from '@ngxs/router-plugin';
import { withNgxsStoragePlugin } from '@ngxs/storage-plugin';

import { TodosState } from '@integration/store/todos/todos.state';
import { TodoState } from '@integration/store/todos/todo/todo.state';
import { TODOS_STORAGE_KEY } from '@integration/store/todos/todos.model';

import { environment } from '../environments/environment';

export const APP_ID_VALUE = 'integration-app';

export const appConfig: ApplicationConfig = {
providers: [
{ provide: APP_ID, useValue: APP_ID_VALUE },

provideRouter([
{ path: '', pathMatch: 'full', redirectTo: '/list' },
{
path: 'list',
loadChildren: () => import('@integration/list/list.module').then(m => m.ListModule)
},
{
path: 'detail',
loadChildren: () =>
import('@integration/detail/detail.module').then(m => m.DetailModule)
},
{
path: 'counter',
loadChildren: () =>
import('@integration/counter/counter.module').then(m => m.CounterModule)
}
]),

provideStore(
[TodosState, TodoState],
{ developmentMode: !environment.production, selectorOptions: {} },
withNgxsFormPlugin(),
withNgxsLoggerPlugin({ logger: console, collapsed: false, disabled: true }),
withNgxsReduxDevtoolsPlugin({ disabled: environment.production }),
withNgxsRouterPlugin(),
withNgxsStoragePlugin({ key: [TODOS_STORAGE_KEY] })
)
]
};
23 changes: 0 additions & 23 deletions integration/app/app.module.ts

This file was deleted.

12 changes: 0 additions & 12 deletions integration/app/app.server.module.ts

This file was deleted.

13 changes: 3 additions & 10 deletions integration/main.server.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
import { enableProdMode } from '@angular/core';

import { environment } from './environments/environment';

if (environment.production) {
enableProdMode();
}

export { AppServerModule } from './app/app.server.module';
export { renderModuleFactory } from '@angular/platform-server';
export { AppComponent } from './app/app.component';
export { appServerConfig } from './app/app-server.config';
export { APP_ID_VALUE } from './app/app.config';
7 changes: 4 additions & 3 deletions integration/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { bootstrapApplication } from '@angular/platform-browser';

import { AppModule } from './app/app.module';
import { AppComponent } from './app/app.component';
import { appBrowserConfig } from './app/app-browser.config';
import { environment } from './environments/environment';

if (environment.production) {
enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule);
bootstrapApplication(AppComponent, appBrowserConfig);
Loading

0 comments on commit d522732

Please sign in to comment.