Backbone Paginator Server Sorting

Recently I had to sort a collection using server mode (that is, doing a fetch for each page). It turns out this was not a simple as it seemed, needing to pass some extra options to the mode switching to stop the state being lost (as I could not set the pagination mode on the parent).

This is because I had some trouble with inheritance since I was using a child and parent collection. Here is the solution I found: (note the options in switchMode)

let parentCollection = Backbone.PageableCollection.extend({
  queryParams: {
    currentPage: ‘current_page’,
    pageSize: ‘page_size’,
    totalPages: ‘count’,
    sortKey: ‘sort’,

let childCollection = parentCollection.extend({
  url: ‘/documents’,
  model: Entities.Document,
  comparator: Entities.DocumentCollectionComparator,

  doSort(field = ‘modified’, mode) {
    this.setSorting(field, mode === ‘des’ ? 1 : -1, {full: true})
    this.switchMode(‘server’, {fetch: true, resetState: false});

Nested Marionette Behaviors

Today I was having trouble with Nested Behaviors in Marionette 2.4.2.

The trouble was, how do I get options into my behaviors in behaviors?

Here is my situation:


  View.Main = Marionette.ItemView.extend({
  behaviors: {
    // named so the sub behavior can access this!
    behaviorName: {
      data: 'someData',
      behaviorClass: BehaviorName,

Then inside of that Behavior:


// Note: using the unnamed array method to describe behaviors here, which came in as of 2.4.1
behaviors: [{
behaviorClass: NestedBehaviorName,

So the problem then, is how do I get these the options from the parent into this sub behavior?

Here is what I ended up with:


  initialize: function() {
    if (this.view.behaviors.BehaviorName) {
      _.extend(this.options, _.pick(this.view.behaviors.BehaviorName, ['data']));

Some recent spam

I got some spam recently, but they must have failed to parse their email correctly, so it came out raw, it is a little bit interesting. Though it was very long, here is a small snippet:

{I have|I’ve} been {surfing|browsing} online
more than {three|3|2|4} hours today, yet
I never found any interesting article like yours.

{It’s|It is} pretty worth enough for me. {In my opinion|Personally|In my view}, if
all {webmasters|site owners|website owners|web owners} and
bloggers made good content as you did, the {internet|net|web} will be {much more|a lot more} useful than ever before.|
I {couldn’t|could not} {resist|refrain from} commenting.
{Very well|Perfectly|Well|Exceptionally well} written!|
{I will|I’ll} {right away|immediately} {take hold of|grab|clutch|grasp|seize|snatch} your {rss|rss feed} as I {can not|can’t} {in finding|find|to find} your {email|e-mail} subscription {link|hyperlink}
or {newsletter|e-newsletter} service. Do {you have|you’ve} any?
{Please|Kindly} {allow|permit|let} me {realize|recognize|understand|recognise|know} {so
that|in order that} I {may just|may|could} subscribe.
{It is|It’s} {appropriate|perfect|the best} time to make some plans for
the future and {it is|it’s} time to be happy. {I have|I’ve} read this post and if I could I {want
to|wish to|desire to} suggest you {few|some} interesting things or {advice|suggestions|tips}.
{Perhaps|Maybe} you {could|can} write next articles referring
to this article. I {want to|wish to|desire to} read {more|even more} things about it!|
{It is|It’s} {appropriate|perfect|the best} time to make {a few|some} plans for
{the future|the longer term|the long run} and {it is|it’s} time to be happy.
{I have|I’ve} {read|learn} this {post|submit|publish|put up} and if I {may just|may|could}
I {want to|wish to|desire to} {suggest|recommend|counsel} you {few|some} {interesting|fascinating|attention-grabbing} {things|issues} or {advice|suggestions|tips}.
{Perhaps|Maybe} you {could|can} write {next|subsequent} articles {relating to|referring to|regarding} this article.

Hope you get the {problem|issue} {solved|resolved|fixed} soon. {Kudos|Cheers|Many thanks|Thanks}|
This is a topic {that is|that’s|which is} {close to|near to} my heart…

Caps lock

Was ranting to grg today about how capslock is the worst key ever invented on a keyboard and how no one has ever used it ever.

Then I googled it, and found some other people agree:

Nice to know.

… the Caps Lock key has been little used, with some people claiming they use it deliberately only once or twice per year.

Publishing a Yeoman generator and its sub generators.

So I have a Yeoman generator that helps scaffold a Backbone.Marionette application using the module paradigm, which is all good.

Though I did get a little caught out when publishing the sub-generator component of it.

That is so you can do things like yo marionette-modules:module aSubModule, to get a module generated.

The :module part was not being registered in the Yeoman package when running yo --help.

The solution in the end is to add all folders you want to deploy into package.json before you publish eg:

“files”: [