On the server – Or don't – What's great?



On the server – Or don't – What's great?

0 0


oboe-js-talk


On Github JuanCaicedo / oboe-js-talk

Oboe.js

Better JSON through streams

Juan Caicedo

What are we going to learn?

Big JSON is hard

Slow page load?

One big AJAX?

Many small AJAX?

npm install oboe

It's this simple

              
oboe('url')
  .node('pattern', function(data){
    // handler code
  });
              
            

Interact on the fly!

Object Oriented?

              
oboe('/myapp/people')
  .node('people.*', function(person){
    return new Person(person.firstName, person.lastName)
  })
  .done(function(people){
    // OOP people!
  })
              
            

Filtering

              
var onlyPeople = [];

oboe('/myapp/people')
  .node('people.*', function(person){

    if(person.name !== 'Duke'){
      onlyPeople.push(person);
    }

  })

  .done(function(){
    console.log(onlyPeople) // no Duke :(
  })
              
            

Memory efficient

oboe('/myapp/people')
  .node('{ firstName lastName }', function(person){

    // write to the DOM

    return oboe.drop;
  })

  .done(function( finalJson){
    console.log(finalJson); // {"people": []}
  })
            

Fail gracefully!

On the server

              
router.get('/data', function(req, res) {

  var readStream = fetchYourData();

  readStream.pipe(res)
});
              
            

Or don't

In the shell

                
$ cat pipelines.json | node rerun-pipelines.js
              
            

In the node

                
oboe(process.stdin)

  .done(function(pipelines){

    pipelines.forEach(rerun)
  })
                
              

What's great?

  • Small footprint
  • Few dependencies

What's bad?

...

Questions?

Oboe.js Better JSON through streams Juan Caicedo