Skip to content

@lends does not work with member expressions like My.Collection #687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sanxac opened this issue Mar 3, 2017 · 3 comments
Open

@lends does not work with member expressions like My.Collection #687

sanxac opened this issue Mar 3, 2017 · 3 comments
Labels

Comments

@sanxac
Copy link

sanxac commented Mar 3, 2017

/**
 * Class representing a Collection of Models
 *
 * @class My.Collection
 * @extends Backbone.Collection
 *
 *
 */
My.Collection = Backbone.Collection.extend({

	/**
	 * Where to access API.
	 *
	 * @type {string} [urlRoot=My.Config.apiUrl] -
	 */
	urlRoot: My.Config.apiUrl,

	/**
	 * Init function
	 *
	 * @type {function}
	 * @param {Object} options - my options
	 */
	initialize: function(options) {
		Backbone.Collection.prototype.initialize.call(this, options);
	},
//.. continues

These 3 comment blocks appear completely separate in the docs. I would expect the 'urlRoot' attribute & 'initialize' function to be grouped with My.Collection class doc. They are all in alphabetical order, meaning I have several 'initialize' functions listed together without any context as I'm extending other Backbone base classes.

@tmcw
Copy link
Member

tmcw commented Apr 24, 2017

Hi Sanja!

Sorry for the delay, looking at this now, the proper solution is:

/**
 * Class representing a Collection of Models
 *
 * @class MyCollection
 * @extends Backbone.Collection
 *
 *
 */
MyCollection = Backbone.Collection.extend(/** @lends MyCollection.prototype */{

	/**
	 * Where to access API.
	 *
	 * @type {string} [urlRoot=My.Config.apiUrl] -
	 */
	urlRoot: My.Config.apiUrl,

	/**
	 * Init function
	 *
	 * @type {function}
	 * @param {Object} options - my options
	 */
	initialize: function(options) {
		Backbone.Collection.prototype.initialize.call(this, options);
	}
});

The @lends tag indicates to documentation.js that the object being passed to Backbone.Collection.extend becomes part of My.Collection's prototype. This isn't something that we can assume always - you might be passing an object of options to some method that makes and arbitrary result here.

^ This example works in my testing, but unfortunately I identified that My.Collection doesn't currently work, whereas MyCollection does. So, marking this as a bug and looking at it now!

@tmcw tmcw added the bug label Apr 24, 2017
@tmcw tmcw self-assigned this Apr 24, 2017
@tmcw tmcw changed the title Subclass attributes and functions are not grouped with main declaration @lends does not work with member expressions like My.Collection Apr 24, 2017
@tmcw tmcw removed their assignment Nov 26, 2017
@maciej-ka
Copy link
Contributor

@tmcw does this look like correct test reproduction?

/**
 * Class representing a Collection of Models
 *
 * @class My.Collection
 * @extends Backbone.Collection
 *
 *
 */
My.Collection = Backbone.Collection.extend(/** @lends My.Collection.prototype */{

	/**
	 * Where to access API.
	 *
	 * @type {string} [urlRoot=My.Config.apiUrl] -
	 */
	urlRoot: My.Config.apiUrl,

	/**
	 * Init function
	 *
	 * @type {function}
	 * @param {Object} options - my options
	 */
	initialize: function(options) {
		Backbone.Collection.prototype.initialize.call(this, options);
	}
});

@maciej-ka
Copy link
Contributor

Perhaps it's linked to #591 (I don't see the whole picture yet)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants