Git Product home page Git Product logo

backbone.obscura's People

Contributors

ddavydov avatar jmorrell avatar mcordingley avatar mulderp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

backbone.obscura's Issues

Add models on proxy

When calling:

 proxy.models

There is "undefined" returned.

So, in case of rendering a collection from a proxy that requires models instead of JSON, having models would make the proxy more complete.

Grouping?

Hey,

i just came across the task of grouping models. Would that make sense to use a proxy for that?

i implement that by creating a new grouped collection and wrapping the collection in a new proxy. but i loose the referenz to the original proxy and can't "reset" the original state.

kalle

Usage with Marionette: on filtering, renders individual ItemView(s) and not Composite/Collection view

Hi there,

Currently, when I add a filter to my obscura collection, the filtered models are being rendered into views one by one, and not by the CompositeView as a collective whole.

I need an event hook for when all the views have finished rendering, and because itemViews are being rendered individually, I don't have a way of knowing when that is.

Collection/Composite views have various onRender events that I could use, except they're not being triggered.

filtering nested collection

I have a collection of models that looks like this:

[
    {
        "id": 1,
        "name": "mike",
        "pets": [
            { "id": 1, "type": "dog" },
            { "id": 2, "type": "cat" }
        ]
    },
    {
        "id": 2,
        "name": "john",
        "pets": [
            { "id": 1, "type": "dog" }
        ]
    }
]

is it possible with obscura to filter the users that have, for example, a cat?

Server pagination

backbone.obscura kick ass when the collection has everything.

But suppose i'm receiving some pagination from an API. My collection has "right now" 50 models, but there are hundreds more on the API.

Did you ever tackle this generic problem with your library or it wasn't designed with this in mind ?

I'm asking because i'm not seeing anything like that in the docs and i'm not seeing some obvious way I could plug in to fetch incrementally from the server when going next/previous page.

Filtered length when paginating

Currently there is no way of knowing how many models are in the collection after filtering if you're also paginating. This is definitely information you may want to show in the UI.

filterBy Array

It would be nice to have some filter by Array function:

movies.filterBy('ratings', [3,4,5]);

Then, all movies that have a rating of 3 OR 4 OR 5, should be returned. It looks a bit familar to

filtered.filterBy('foo and bar filter', { foo: 2, bar: 3 }) 

but with an Array.

What do you think? I can try a PR for this.

Cheers.

'filtered:add' event is triggered before the collection is filtered

The filtered:add event is triggered in addFilter method, but addFilter method is executed before execFilter.

filterBy: function (filterName, filter) {
    if (!filter) {
        filter = filterName;
        filterName = this.defaultFilterName;
    }
    addFilter.call(this, filterName, createFilter(filter));
    execFilter.call(this);
    return this;
},

I think that filtered:add should be triggered when the collection is already filtered.

Obscura does not extend Backbone.Collection

I'm sure this is by design but I'm a bit confused as to why. For this to really work in all cases the object itself should be instanceof Backbone.Collection. There are some libraries (Backbone.Epoxy for example) that accept collections and check if they are an instance of Backbone.Collection. If they are not, they do not work.

Support Multiple Base Collections

Hi there,

I've run into a situation where what I need is essentially an instance of Obscura, but one that merges multiple collections together. The specific use case is a combined list of "things" being fed into a Marionette CollectionView and collectively sorted by date.

I have a (currently broken) proof of concept at https://gist.github.com/mcordingley/7900358 based somewhat on some of your code.

It would be awesome if this sort of thing could make it into Obscura.

Thanks,
-Michael

Unnecessary sorting on change between models with same comparators

Lets say we have a collection sorted on attribute 'name', and there are 4 entries with the name "Bob", if we change some other attribute, say 'age' on the second "Bob", it will remove that one and insert it at the beginning or the end of the "Bob"s, depending on directionality.

Cause:
If we consider line https://github.com/jmorrell/backbone.obscura/blob/master/backbone.obscura.js#L641, the algorithm checks to see where it would be inserted, and if its current index is different from the new index. However this doesn't take into account whether the comparator of the model at the new index is different from the comparator of the model in question. If they are the same, they shouldn't be resorted.

This can cause very disruptive changes, especially when there's a small number of unique comparators compared to the size of the list.

Proxy Collection retrieved is only of single element

I'm using backbone obscura in my application.

In my require_main.js inside paths I've
'backbone.obscura':'lib/backbone.obscura',
and in shim I've
'backbone.obscura' : {
deps : [ 'underscore', 'backbone' ],
exports : "Obscura"
}

I'm pulling in obscura in one of my Marionette view
define(['backbone.obscura'], function(Obscura){
// code for view creation. Edited for brevity

showTable : function(){
console.log(this.collection.length); // prints the length of collection which is 10
var proxy = new Obscura(this.collection);
console.log(proxy.length); // prints the length of proxy which is one (1) // remaining 9 are not retrieved
var view = new Collectionview({collection : proxy});
}
});

Could you please suggest any approach to figure out this issue?

Model change event not working after filtering

I currently have a 'change' event on my model which works fine until I do any filtering.

in my collection entity I have:

initialize: ->
  @on("change:selected", @toggleSelected)

toggleSelected: (selectedModel, isSelected) ->
  if isSelected
    _.each @models, ((model) ->
      model.deselect() if selectedModel isnt model
    )

and this is how I've initialized my collection

contacts = new Entities.ContactsCollection
contacts.fetch
  reset: true

@contacts = new Backbone.Obscura(contacts)
@contacts

Is there a reason why the model 'change' event is not working within obscura?

GroupBy / Filtering out Duplicates

As the title suggest - do you have any thoughts on how Obscura might be extended to allow for those two use cases:

  1. GroupBy Proxies - Grouping collections into groups of collections per an attribute value - eg. all delivery models with the same 'date' attribute get placed into a 'collection' attribute on a new model, that's part of the proxy collection. This works great with Marionette where a collection view can use another collection view for it's itemView.
  2. Filtering out Duplicates - is it possible to use filterby (or a variation) to filter out all duplicates from a collection based on an attribute value

Thanks!

Complex setSort() callback

@jmorrell Great work on this library!

One thing I'd like to do is perform sorts using a compareFunction comparator callback similar to how Array.prototype.sort does it. The callback provides two models as arguments (a and b), and the result of the function is whether A is greater than B, vice-vera, or they're equal. This allows you to do much more complex sorts that are multi-layered and don't have to rely on string comparison.

The following issue calls out this issue as it originally appeared in Backbone. The ability to provide a compareFunction-like sort comparator has since been added.

jashkenas/backbone#488

Would this be difficult to add? I might look into doing it if I get some time soon.

Model change events causing a remove/add on collection

I'm not actually sure if there's something I'm doing wrong, but for all my Obscura collections, when a change event is fired on the superset collection (e.g. a model's properties have been changed), the model being changed moves to the bottom of the collection.

Backbone.Obscura calls the following code:

function onChange(model) {
  if (this.contains(model)) {
    this._collection.remove(model);
    onAdd.call(this, model);
  }
}

which means that the model is removed, then re-added to the list. Though it looks like it's index is being retained in the onAdd method, so I'm not sure what is going on.

If a model's property changes, does the collection need to remove/add it? Shouldn't the model already have the change?

Any thoughts?

Update for Backbone v1.1.0

Based on a quick test, it looks like the only conflict with the new version of backbone is the removal of Collection#sortedIndex. This should be pretty easy to remedy.

Bower.json version doesn't match package.json version as of 1.0.0

Minor noise during bower install

bower backbone.obscura#~1.0.0         mismatch Version declared in the json (0.1.7) is different than the resolved one (1.0.0)

Too late to fix it for 1.0.0 since that's already tagged+published but maybe something to add to a release checklist (mental or otherwise) for future releases.

Alphanumeric Sorting

I am unable to sort alphanumeric strings by using sortBy function. Could you look in to that one.

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.