From 6719e8bce4b8067384ccee491728b566a48c0839 Mon Sep 17 00:00:00 2001 From: igor-dv Date: Sun, 18 Mar 2018 15:35:35 +0200 Subject: [PATCH] Add example for @ngrx/store --- examples/angular-cli/package.json | 1 + .../ngrx-store.stories.storyshot | 31 +++++++++++++++++++ .../src/stories/ngrx-store.stories.ts | 17 ++++++++++ .../src/stories/ngrx/WithStoreComponent.ts | 18 +++++++++++ yarn.lock | 4 +++ 5 files changed, 71 insertions(+) create mode 100644 examples/angular-cli/src/stories/__snapshots__/ngrx-store.stories.storyshot create mode 100644 examples/angular-cli/src/stories/ngrx-store.stories.ts create mode 100644 examples/angular-cli/src/stories/ngrx/WithStoreComponent.ts diff --git a/examples/angular-cli/package.json b/examples/angular-cli/package.json index cd7e0478f003..5925524540e7 100644 --- a/examples/angular-cli/package.json +++ b/examples/angular-cli/package.json @@ -19,6 +19,7 @@ "@angular/forms": "^5.2.9", "@angular/platform-browser": "^5.2.9", "@angular/platform-browser-dynamic": "^5.2.9", + "@ngrx/store": "^5.2.0", "core-js": "^2.4.1", "rxjs": "^5.5.7", "zone.js": "^0.8.20" diff --git a/examples/angular-cli/src/stories/__snapshots__/ngrx-store.stories.storyshot b/examples/angular-cli/src/stories/__snapshots__/ngrx-store.stories.storyshot new file mode 100644 index 000000000000..7891f51327e7 --- /dev/null +++ b/examples/angular-cli/src/stories/__snapshots__/ngrx-store.stories.storyshot @@ -0,0 +1,31 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Storyshots ngrx|Store With component 1`] = ` + + +
+ Store is injected +
+
+
+`; + +exports[`Storyshots ngrx|Store With template 1`] = ` + + + +
+ Store is injected +
+
+
+
+`; diff --git a/examples/angular-cli/src/stories/ngrx-store.stories.ts b/examples/angular-cli/src/stories/ngrx-store.stories.ts new file mode 100644 index 000000000000..1e703d87adc3 --- /dev/null +++ b/examples/angular-cli/src/stories/ngrx-store.stories.ts @@ -0,0 +1,17 @@ +import { StoreModule } from '@ngrx/store'; +import { storiesOf, moduleMetadata } from '@storybook/angular'; +import { WithStoreComponent } from './ngrx/WithStoreComponent'; + +storiesOf('ngrx|Store', module) + .addDecorator( + moduleMetadata({ + imports: [StoreModule.forRoot({})], + declarations: [WithStoreComponent], + }) + ) + .add('With component', () => ({ + component: WithStoreComponent, + })) + .add('With template', () => ({ + template: ``, + })); diff --git a/examples/angular-cli/src/stories/ngrx/WithStoreComponent.ts b/examples/angular-cli/src/stories/ngrx/WithStoreComponent.ts new file mode 100644 index 000000000000..3857bc41c103 --- /dev/null +++ b/examples/angular-cli/src/stories/ngrx/WithStoreComponent.ts @@ -0,0 +1,18 @@ +import { Component } from '@angular/core'; +import { Store } from '@ngrx/store'; + +@Component({ + selector: 'storybook-comp-with-store', + template: '
{{this.getSotreState()}}
', +}) +export class WithStoreComponent { + private store: Store; + + constructor(store: Store) { + this.store = store; + } + + getSotreState() { + return this.store === undefined ? 'Store is NOT injected' : 'Store is injected'; + } +} diff --git a/yarn.lock b/yarn.lock index 098dd5d50671..2a492ea4a6a7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -214,6 +214,10 @@ lodash "^4.2.0" to-fast-properties "^2.0.0" +"@ngrx/store@^5.2.0": + version "5.2.0" + resolved "https://registry.yarnpkg.com/@ngrx/store/-/store-5.2.0.tgz#627ed74c9cd95462930485d912a557117b23903e" + "@ngtools/json-schema@1.2.0": version "1.2.0" resolved "https://registry.yarnpkg.com/@ngtools/json-schema/-/json-schema-1.2.0.tgz#06e5ecd29e9a37d260a447dd873ea2becd228c4f"