marionettejs / backbone.babysitter Goto Github PK
View Code? Open in Web Editor NEWManage child views for your Backbone.View (and other parents)
License: Other
Manage child views for your Backbone.View (and other parents)
License: Other
Hello,
Jam lists version 0.0.5 of backbone.babysitter and I'd be happy to see the latest one available - 0.0.6 at the moment.
I'd be happy to help pushing this version - but only one of the owners can do it on jam.
Regards,
Ludovic LANGE
In favor of just invoke
. Thoughts @marionettejs/marionette-core ?
Related: #56
Please delegate the reduce
method to the child views.
I have a desire to find a view by its underlying model's id. Backbone allows you specify the value of this with the idAttribute in order to store a unique key relevant to a back-end service.
I realize I could achieve this by essentially doing:
container.add(aView, "id");
However, using Marionette's CompositeView or CollectionView, the container's add is called within an function that isn't easily overridden (and don't really want to).
addItemView: function(item, ItemView, index){
var itemViewOptions = Marionette.getOption(this, "itemViewOptions");
if (_.isFunction(itemViewOptions)){
itemViewOptions = itemViewOptions.call(this, item, index);
}
var view = this.buildItemView(item, ItemView, itemViewOptions);
this.addChildViewEventForwarding(view);
this.triggerMethod("before:item:added", view);
this.children.add(view);
this.renderItemView(view, index);
if (this._isShown){
Marionette.triggerMethod.call(view, "show"):
}
this.triggerMethod("after:item:added", view);
},
Since, the 'id' attribute of the model is defined by Backbone, I think it would worthwhile to add the capability to find the view by the attribute if defined.
I think this could easily be achieved by simply adding a new index object.
this._indexByModelId = {};
add: function(view, customIndex){
...
// index it by model
if (view.model){
...
// add index by model id if present
if(view.model.id) {
this._indexByModelId[view.model.id] = viewCid;
}
}
...
}
...
findByModelId: function(modelId){
var viewCid = this._indexByModelId[modelId];
return this.findByCid(viewCid);
},
...
Looks as though v0.1.12 contains a bower.json that marks it as v0.1.11. This in itself is not too much of an issue as only results in:
bower backbone.babysitter#* mismatch Version declared in the json (0.1.11) is different than the resolved one (0.1.12)
However, since v0.1.11 has a different version dependency of Backbone, it actually ends up using Backbone v1.2.3 (as defined in v0.1.11 bower.json) rather than the Backbone v1.3.3 (as defined in v0.1.12)
I hope that it is easy to update the tag and correct the version that bower downloads?
Thanks,,
Please keep backbone / jquery version dependencies in sync with backbone.marionette.
It's very important for those using npm like with browserify otherwise multiple backbone will be used and babysitter will be attached to one backbone, but marionette to another and marionette will have an undefined backbone.babysitter.
When using ck86/main-bower-files to load marionette, the load order is broken because babysitter doesn't have its dependencies properly declared, loading it before Backbone. Adding the dependencies solves the problem.
-- snip --
"dependencies": {
"backbone": ">=0.9.9 <=1.1.2",
"underscore": ">=1.3.3 <=1.6.0"
},
-- /snip --
This doesn't render any views, correct? It's just a means of storage for views?
It seems to me that the backbone babysitter should listen for close events on the parent view, enabling any user of the babysitter to take advantage of complete sub-view lifecycle. It's great to have that lifecycle management in CollectionView and CompositeView, and it would be even better to be able to harness it for other cases.
Would you accept a patch that refactors the ChildViewContainer and the CollectionView to move the child-view closing responsibility to the ChildViewContainer, perhaps by passing it an optional parent view in the second arg to the constructor? Or will it be necessary to have a separate entity responsible for child-view closing (e.g. due to memory-management issues)?
Note tree at https://github.com/marionettejs/backbone.babysitter/tree/v0.1.1
Observe package.json
has 0.1.1 as version
Observe bower.json
has 0.1.0 as version
Could the tag be reapplied at commit d3383f1ad
Oh wait, there's a v0.1.1-1 tag. Hmm. This is messing up a bower install as the marionette dep is resolving as v0.1.1 and so the AMD change in #39 is not happening.
IE8- doesn't accept undefined
as valid second parameter for Function#apply method.
Working solution should be change one line in Container#apply to: view[method].apply(view, args || []);
Improve ability to add at certain position like in a native Backbone.Collection
var view = new View()
children.add(view, {at: 2})
We've integrated babysitter
into Mn directly (thanks to @paulfalgout). Do we need to continue support this babysitter
as separate lib?
@marionettejs/marionette-core any things?
Needed to fix bower. Also we need to make sure the build file version gets updates as well.. That looks manual and it still says 0.1.11.
Hey all,
I have a function like this in the example:
container.each(function(view){
// process each view individually, here
});
Is there a way to reach 'view' without declaring a function in the loop? I'm trying to make my code JSLint compliant, and I can't figure out if there's a solution to this.
Say I have a collection of models like this one:
var itemsCollection = new Backbone.Collection([{name: 'item1'}]);
And a collection view:
var itemsView = new Marionette.CollectionView({
collection: itemsCollection,
itemView: Marionette.View
});
Then I add a new item into the collection at index 0
itemsCollection.add({name: 'item0'}, {at:0});
Now itemsView
is going to create a new item view with the new model {name: 'item0'}
but the problem is that it will not get indexed with 0 in the children
collection
So if I called itemsView.children.findByIndex(0)
I will get back the view that has the model {name: 'item1'}
instead of the one that has {name: 'item0'}
I can get around this issue if I do itemsView.children.findByModel(itemsView.collection.at(0))
but I was hopping itemsView.children.findByIndex(0)
could just work
Thanks
As per the discussion over at marionettejs/backbone.marionette#1078 we should deprecate findByIndex
In bower.json, the Backbone version range has been defined as ">=0.9.9 <=1.3.x"
. The <=1.3.x
part is not resolved as one would expect, and installs a 1.2.x version. So we get Backbone 1.2.3 instead of the latest 1.3.x.
You can either make it >=0.9.9 <1.4
or set the range as 0.9.9 - 1.3.x
. Both work.
package.json:
"dependencies": { "backbone": ">=0.9.9 <=1.3.2", "underscore": ">=1.4.0 <=1.8.3" },
bower.json:
"dependencies": { "backbone": ">=0.9.9 <=1.2.3", "underscore": ">=1.4.0 <=1.8.3" },
P.S. The same problem in backbone.wreqr library, that's why i can't use backbone v.1.3.2
We should update the peerDependencies for babysitter for the Mn v3 release. I think we can get away with possibly setting less restrictions on this library that maybe we would for Mn.
Possibly just:
"peerDependencies": {
"backbone": "^1.3.3",
"underscore": "^1.8.3"
}
Since they're peer Deps anyone could still install older versions, but it would just complain on npm i.
call
seems to be a redundant implementation of invoke
.
Something is wrong with this lib (or with me), I can't make it work, trying to use it with my project without marionette, using require.js to load, but I get the following error.
the main.js file looks like this:
requirejs.config({
paths: {
'underscore': 'lib/underscore',
'backbone': 'lib/backbone',
'backbone.babysitter': 'lib/backbone.babysitter',
'jquery': 'lib/jquery',
},
shim: {
underscore: {
exports: '_'
},
backbone: {
deps: ['underscore','jquery'],
exports: 'Backbone'
}
}
});
and where I want to use:
require( ['backbone.babysitter'], function(){
var v = Backbone.ChildViewContainer();
});
debugging the code I find that the _updateLength()
is added to the Container.prototype
, while this
in
var Container = function(views){
this._views = {};
this._indexByModel = {};
this._indexByCustom = {};
this._updateLength();
_.each(views, this.add, this);
};
refers to Backbone.ChildViewContainer
What's going on here?
XRef: marionettejs/backbone.marionette#2889
A few methods using context.
_.tail
an issue?
One _.any
Might be others.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.