How does set.comparators.sort('sortBy') work?

as a short describtion on https://github.com/canjs/can-set
i really dont understand how set.comparators.sort(‘sortBy’)

here is a example: http://jsbin.com/daqavakijo/2/edit?html,js,console,output

why is dishes not the first item?

why is dishes not the first item?

It is the first item. But I think you mean “why is dishes the first item instead of agym?”.

The reason is that the sort operator does not actually sort the response from the server in this scenario. It expects the server did the sorting. The server is returning:

[
        {_id: 0, name: "dishes"},
        {_id: 3, name: "agym"}
      ]

So that’s the order items are added to the resulting list.

The reason is that the sort operator does not actually sort the response from the server in this scenario.

In fact, for an initial .getList(set) , no filtering, sorting, pagination takes place. It assumes the server did all of that.

Only on other requests, assuming you are using superMap or its extensions like real-time or fall-through-cache, is the set used to make comparisons.

sorry posted the wrong example
here the updated: http://jsbin.com/xutepuyuxi/1/edit?html,js,console,output

so if the sort.algebra does not sorting, why does it exists?

can you give me a example in jsbin?

this example with a new todo didnt work: http://jsbin.com/lupatadisu/1/edit?html,js,console,output

It exists for extensions that make use of getSubset or getUnion or index.

In bitballs, when a new player is created, it’s added in its sorted place in the list of players.

It didn’t work because you didn’t request a sorted list from the server. You passed it {}. The default sorting will then be by the id prop.

@justinbmeyer can you make my example working?
i am still not understand the behavoir

I just changed it to:

Todo.getList({sortBy: "name"})

@justinbmeyer so the sortBy will be send as query param? like myhost.biz/todos?sortBy=name

yes, that is what will happen.