Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subject.create error #483

Closed
Rayman opened this issue Oct 8, 2015 · 4 comments
Closed

Subject.create error #483

Rayman opened this issue Oct 8, 2015 · 4 comments
Assignees
Labels
bug Confirmed bug

Comments

@Rayman
Copy link

Rayman commented Oct 8, 2015

I'm having trouble with Subject.create, it keeps throwing an error.

/home/username/src/RxJS/dist/cjs/Observable.js:134
        return this.source._subscribe(this.operator.call(subscriber));
                                                   ^

TypeError: Cannot read property 'call' of undefined
    at BidirectionalSubject._subscribe (/home/username/src/RxJS/dist/cjs/Observable.js:134:52)
    at BidirectionalSubject._subscribe (/home/username/src/RxJS/dist/cjs/Subject.js:186:37)
    at BidirectionalSubject.subscribe (/home/username/src/RxJS/dist/cjs/Observable.js:103:29)
    at Object.<anonymous> (/home/username/src/roslib-rx/dist/index.js:78:13)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:475:10)
    at startup (node.js:118:18)

Here is the code I used. I'm trying to create a subject where I can both send and receive. Is this a bug or am I using the wrong method?

class ReceiveTopic {
  constructor(options) {
    return new Observable(obs => {
      console.log('sub to ReceiveTopic');

      setTimeout(() => {
        // simulate a value that is received
        obs.next('receive value from topic');
      }, 500);

      return () => {
        console.log('unsub from ReceiveTopic');
      }
    });
  }
}

class SendTopic {
  constructor(options) {
    return Subscriber.create(
      function (data) {
        console.log('send data:', data)
      },
      function(e) {
        console.error('send error:', e);
      },
      function() {
        console.log('send done');
      }
    );
  }
}

const topic1 = new ReceiveTopic();
const topic2 = new SendTopic();

const duplexTopic = Subject.create(topic1, topic2);

duplexTopic.subscribe(Subscriber.create(
  function(e) {
    console.log('message:', e);
  },
  function(e) {
    // errors and "unclean" closes land here
    console.error('error: ', e);
  },
  function() {
    // the socket has been closed
    console.info('socket closed');
  }
));

duplexTopic.next('send data to topic');
@benlesh
Copy link
Member

benlesh commented Oct 8, 2015

I'm assuming this is in alpha.2? I'll take a look... thanks.

@benlesh benlesh self-assigned this Oct 8, 2015
@benlesh benlesh added the bug Confirmed bug label Oct 8, 2015
@benlesh
Copy link
Member

benlesh commented Oct 8, 2015

Looking at this, it looks like create() isn't doing what it should. This is a bug. Thanks for finding this.

@benlesh benlesh closed this as completed in 2259de2 Oct 8, 2015
@Rayman
Copy link
Author

Rayman commented Oct 9, 2015

Thanks guys, Subject.create works fine now for my use case.

@benlesh
Copy link
Member

benlesh commented Oct 9, 2015

👍 no, thank you for finding a bug!

@lock lock bot locked as resolved and limited conversation to collaborators Jun 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Confirmed bug
Projects
None yet
Development

No branches or pull requests

2 participants