svi3c / rx-simple-store

A simple rx store solution written in TypeScript
MIT License
6 stars 1 forks source link

How to use operator ? #1

Open ball6847 opened 6 years ago

ball6847 commented 6 years ago

I've tried rx-simple-store with angular4 and it work very well, except one thing, I cannot get rxjs operators to work with the store class.

import { Component } from '@angular/core'
import { AppStore } from './store'
import 'rxjs/add/operator/map'

@Component({
  selector: 'app',
  template: 'app component',
})
export class AppComponent {
  constructor(private store: AppStore) {
    this.store
      .map(x => x.item)
      .subscribe(x => {
        console.log(x)
      })
  }
}

this will raise an error:

Property 'map' does not exist on type 'AppStore'

The installed version is ^0.3.0

Please advice, Thanks

ball6847 commented 6 years ago

update

I managed to make it work. This seem to be an issue with yarn package manager. I installed via npm install rx-simple-store --save
And it worked as expect. But it's not working with yarn.

$ yarn --version             
0.27.5

$ npm --version                     
4.1.2
svi3c commented 6 years ago

Hi @ball6847,

that's a strange behavior. I just created a new project, added rx-simple-store and copied over the example from the README.md. Then I added a simple

todoStore.do(console.log).subscribe();

and imported the operator from rxjs/add/operator/do. It worked as expected.

I'm using yarn 1.2.1, but it should not matter, since it's all compiled via typescript anyways.

You could try to remove node_modules and do a yarn cache clean && yarn.