rhysbrettbowen / backbone.advice Goto Github PK
View Code? Open in Web Editor NEWFunctional mixins for Backbone based on Advice by Angus Croll
License: Other
Functional mixins for Backbone based on Advice by Angus Croll
License: Other
myMixin = function() {
return { foo: function() { return "My foo result" }
}
myOtherClass = function() {}.mixin(myMixin); // mumble - point is, it doesn't have 'foo'.
myOtherClass.foo("some arg"); // returns "some arg"
I expected this to return "My foo result".
Currently, I have to specify 'clobber' for a function name that didn't exist before, because the identity function's return value is returned instead of my function's return value. Surprise! and :(
I'd sort of hope that after
would recognize the no-original-method case, and take a shortcut whereby we just create the method with direct reference to the new method. Methods aside, the outcome still seems wrong.
First, great project!
It should be interesting if we could pass to addToObj names of prototype functions that return an object, and do the extend with this value, so we could declare for example events as a function(which return an object) as it is usual in backbone for easy inheritance method overloading.
I really like the way Cocktail patches the extend method so that mixin includes can be written far more clearly (imho) in the form;
var MyView = Backbone.View.extend({
mixins: [MyMixin1, MyMixin2],
etc...
});
Any chance of similar in Advice?
I just installed Karma to try to get the tests to run and it seems that Karma has changed their config file format, and the tests won't run out of the box.
Steps to reproduce:
sudo npm install -g karma
karma start
I get this error:
ERROR [config]: Config file must export a function!
module.exports = function(config) {
config.set({
// your config
});
};
I also did some investigation and tried version 0.8.4 of Karma (the version available around the time the last commit to karma.conf.js
was made), and I ran into a problem actually running the test.
Steps to reproduce:
sudo npm install -g phantomjs
sudo npm install -g [email protected]
karma start
I get this error:
PhantomJS 1.9 (Linux) Backbone.Advice should be able to override mixin options should not override only on tha applied constructor FAILED
expected 2 to equal 3
I don't know if this relates to using the latest version of PhantomJS or not. I have not tried a previous version of PhantomJS to coincide with 0.8.4 of Karma.
We are using JSHint and modules with Advice. It all works pretty well; however, JSHint will complain about "possible strict violations." This is basically just hurting my feelings ha.
Have you found a good solution to get around all the linting warnings?
I'm running into a problem in which I'm mixing two methods into a view, one of which needs a value returned by the other. The problem is, the second method always returns undefined
. You can test this pretty easily by running this code in your console:
Backbone.View.mixin({
callee : function () {
return "some value";
},
caller : function () {
console.log(this.callee());
}
});
new Backbone.View().caller(); // undefined
I'm trying to investigate the cause further; I'll update this issue when and if I figure out more.
Could you please add a "Backbone.Advice" object availability check in order to avoid recurrent module initialization
if (Backbone.Advice) {
return false;
}
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.