DailyJS

Impossible Mission, Full-Text Indexing, Backbone.Projections

Alex R. Young

Subscribe

@dailyjs

Facebook

Google+

pdf games node backbone.js

Impossible Mission, Full-Text Indexing, Backbone.Projections

Posted by Alex R. Young on .
Featured

pdf games node backbone.js

Impossible Mission, Full-Text Indexing, Backbone.Projections

Posted by Alex R. Young on .

Impossible Mission

Impossible Mission

Impossible Mission by Krisztián Tóth is a JavaScript remake of the C64 classic. You can view the source to see how it all works, if things like this.dieByZapFrames and this.searchedFurniture sound appealing to you.

Krisztián previously sent in Boulder Dash and Wizard of Wor which were similar remakes written using the same approach.

Client-Side Full-Text Indexing

Gary Sieling sent in a post he wrote about full-text indexing with client-side JavaScript, in which he looks at PDF.js and Lunr: Building a Full-Text Index in JavaScript. I briefly mentioned Lunr by Oliver Nightingale back in March.

One great thing about this type of index is that the work can be done in parallel and then combined as a map-reduce job. Only three entries from the above object need to be combined, as "fields" and "pipeline" are static.

Backbone.Projections

In relational databases, a projection is a subset of available data. Backbone.Projections (GitHub: andreypopp / backbone.projections, License: MIT, npm: backbone.projections) by Andrey Popp is the equivalent for Backbone collections -- they allow a transformed subset of values in a collection can be represented and synced.

The supported projections are Capped and Filtered. Capped collections are limited based on a size and function -- the function will be used to order the results prior to truncating them. Filtered projections filter out results based on a function that returns a boolean.

Projections can be composed by passing one project to another. This example creates a Filtered projection, and then passes it to a Capped projection to limit and order the results:

var todaysPosts = new Filtered(posts, {  
  filter: function(post) {
    return post.get('date').isToday();
  }
});

var topTodaysPosts = new Capped(todaysPosts, {  
  cap: 5,
  comparator: function(post) {
    return post.get('likes');
  }
});

The author has written unit tests with Mocha, and documentation is available in the readme.