GithubHelp home page GithubHelp logo

Streaming able ? about coffeekup HOT 7 OPEN

clyfe avatar clyfe commented on July 17, 2024
Streaming able ?

from coffeekup.

Comments (7)

clyfe avatar clyfe commented on July 17, 2024

Having said that, my main attraction to CoffeeKup is using it as a "helper language" inside sam's Eco meaning
Eco does the templateing (streamable) and CK does view helping.

Rails

<%= content_tag 'div', class: 'some_class' ... %>

CoffeeKup

<%=ck -> div class: 'some_class' ... %>

from coffeekup.

mauricemach avatar mauricemach commented on July 17, 2024

I'm not really familiar with template streaming, but I don't think there should be a problem. No, we don't have to wait for the whole thing to return to get the output; as each function is executed it writes to a buffer. At this moment we might as well fire an event with the chunk, don't we?

I couldn't find any examples on streaming with Eco, nor support for it in its source code, but if you could point me in the right direction I'd be glad to study it and see what can be done in CoffeeKup.

from coffeekup.

clyfe avatar clyfe commented on July 17, 2024

Indeed you are right. That's awesome.
I don't think Eco does streaming at this point, I just thought that it's definitively possible, since Rails 3.1 (ERB) did it and ERB and Eco are similar.

from coffeekup.

mauricemach avatar mauricemach commented on July 17, 2024

OK! So, I think this could make it into 0.3.0 final. What do you think of this API (completely stolen from dustjs):

compiled_template(foo: 'bar', options: {stream: yes})
  .on('data', (data) -> console.log data)
  .on('end', -> console.log "c'est fini!")
  .on('error', (err) -> console.log 'doh!')

from coffeekup.

clyfe avatar clyfe commented on July 17, 2024

Looks good, conforms to node de facto conventions. I wander if the buffer object can also be given as an option (optional).

compiled_template(foo: 'bar', options: {stream: yes, buffer: res})

and this way have the results sent directly to a http.ServerResponse object, no additional plumbing. Ofc. res should respond to data, end and error.

from coffeekup.

mauricemach avatar mauricemach commented on July 17, 2024

How would that work exactly? We'd call res.write and res.end directly?

from coffeekup.

clyfe avatar clyfe commented on July 17, 2024

Yes that's what I was thinking. The interface for the buffer should be http://nodejs.org/docs/v0.5.1/api/streams.html#writable_Stream mainly the stream.write(...) and stream.end(...).
If a buffer isn't explicitly given use something internally, so it works both on server and client.

from coffeekup.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.