A little pseudo code to explain the title:
Subject source = new Subject();
function sendInNewResource(newNumber, anotherVariable) {
source.next(newNumber);
}
const newSource = source
.map((myNumber) => myNumber++);
newSource.subscribe((data) => {
//How can I access myObject here?
});
sendInNewResource(1, {myObject});
I think the pseudo code explains a little of what I want to do. So far, I've tried extending the observable, but if I did that it looks as though I'd need to override the operators within the observable.
I almost want to provide metadata to the event.
I do not want to pass the myObject down as this is a library for use externally, I will be subscribing to the observables within my codebase but chaining the observable will be done externally.
Anyone have any ideas on how to achieve this?
For context, I'm trying to create a purely RxJs http library that will allow me to do the following:
const server$ = RxHttpServer(server)
const api$ = server.filter((request) => request.url.startsWith('/api'));
const apiEndpoint$ = api.map(() => ({
status: 400,
body: 'this is an api endpoint',
headers: {
}
}));
// Inside my library, note the use of the response object that I don't have access to:
apiEndpoint.subscribe((dataToSend) => response.write(dataToSend))
The inner logic and handling of these objects has already been written, just need that response object to send back to.