Chat example javascript question

Hi Guys. Back again with the newbie questions. I have not been able to spend a great deal of time researching EventStore, but I’m back at it recently looking at the chat example and trying to figure out how it works.

The question I have is on projections. I had an understanding of them but I now think its incorrect. Originally I thought projections were internal to event store, i.e. the admin somehow loaded some javascript into the event store and then the event store runs all the events through the projection code creating a new (virtual?) stream exposing the projection to the outside world.

From looking at the chat example I think I may have that wrong. It appears that the projection is setup in the client. I.e. if I open the chat example and enter a room name that does not yet exist, call it ‘boo’, the client side seems to start a projection (es.projection.js::startProjection()) which will then setup and listen to the stream chat-boo. I still have some digging with how it does that.

I guess my question is, are projections client side or server side? I.e. Do I need to identify a projection and load it into the server and then all clients get access to the projection, or does each client need to setup the projection and the code runs client side? Perhaps they are a mixture of both?

Another possibility which I just thought of is the client side javascript library might be filtering events client side, giving the appearance of a projection, but maybe not strictly an EventStore projection per-se. I am now suspecting this. Perhaps I can get some clarification before I start second-guessing too many things.

Thanks again

Matt.

Projections are written in js they can be hosted in a browser or internally to the event store

Hi Matt,

See my replies inline.

The question I have is on projections. I had an understanding of them but I now think its incorrect. Originally I thought projections were internal to event store, i.e. the admin somehow loaded some javascript into the event store and then the event store runs all the events through the projection code creating a new (virtual?) stream exposing the projection to the outside world.

You are correct, projections are normally run within the Event Store in V8. They are stored in a stream ($projection-projectionname), and can write events and links to other streams.

From looking at the chat example I think I may have that wrong. It appears that the projection is setup in the client. I.e. if I open the chat example and enter a room name that does not yet exist, call it 'boo', the client side seems to start a projection (es.projection.js::startProjection()) which will then setup and listen to the stream chat-boo. I still have some digging with how it does that.

The chat sample is not using any projections internally - instead it runs the projection on the client (it’s just JavaScript after all), and reads the atom feeds to get events to run through it.

I guess my question is, are projections client side or server side? I.e. Do I need to identify a projection and load it into the server and then all clients get access to the projection, or does each client need to setup the projection and the code runs client side? Perhaps they are a mixture of both?

They can be either or both. Clients actually need no involvement in projections beyond the initial setup phase - but you can run the code locally if you want to. This is how we can, for example, use Chrome as a debugger.

Another possibility which I just thought of is the client side javascript library might be filtering events client side, giving the appearance of a projection, but maybe not strictly an EventStore projection per-se. I am now suspecting this. Perhaps I can get some clarification before I start second-guessing too many things.

You could also do this, but then you drag all the data across a network boundary. One of the big advantages of running your projections in the Event Store is data locality.

Cheers,

James

Awesome guys. Thanks for the replies

Matt

Hi there,

This is going to sound stupid - but where is this chat sample? I can’t find any samples anywhere :confused:

Cheers,

Simon

Hi Simon,

you have to start a node of EventStore, and open http://127.0.0.1:2113 in your browser.

Greets,

Sebastian