Skip to content

Subject.create error #483

Closed
Closed
@Rayman

Description

@Rayman

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');

Metadata

Metadata

Assignees

Labels

bugConfirmed bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions