Skip to content
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

Items model #170

Closed
wants to merge 19 commits into from
Closed

Items model #170

wants to merge 19 commits into from

Conversation

lc-thomasberger
Copy link
Member

@lc-thomasberger lc-thomasberger commented Apr 4, 2017

_isActive attribute is added to _items Array. This attributes are managed by funcitons defined in the itemsModel.
The setter functions trigger a change event change_items:_isActive. Views listen to this event and hande Dom updates. Plugins can use the functions on the itemsModel to manipulate the state of the Component.

defaults: function() {
return _.extend({
_activeItem: 0
}, ItemsModel.prototype.defaults);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you assume nothing is known about ItemsModel.prototype.defaults apart from what is described in the Backbone API, it could be a function or an object.

Can you instead use _.result(ItemsModel.prototype, "defaults"); here just in case we have to change the way defaults is defined on the itemsModel later?

It's equivalent of doing typeof ItemsModel.prototype.defaults == "function" ? ItemsModel.prototype.defaults() : ItemsModel.prototype.defaults;

http://underscorejs.org/#result

var NarrativeModel = ItemsModel.extend({

defaults: function() {
return _.extend({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_.extend overwrites object attributes from right to left. If the ItemsModel was to define an _activeItem:1 it would overwrite this NarrativeModel _activeItem:0. These arguments should be inverted so that this model overwrites the defaults from the ItemsModel:

_.extend(ItemsModel, NarrativeModel);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_.extend({}, ItemsModel, NarrativeModel);

remove oncomplete as it not used anymore
use _.result for itemsModel defaults
},

checkCompletionStatus: function() {
ItemsModel.prototype.checkCompletionStatus.apply(this, arguments);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line can go as this function overrides the behaviour of ItemsModel, the completion for Narrative is handled by the narrative, either inview or allItems

@@ -6,9 +6,9 @@ define([
var NarrativeModel = ItemsModel.extend({

defaults: function() {
return _.extend({
return _.extend(_.result(ItemsModel.prototype, "defaults"), {
Copy link
Member

@oliverfoster oliverfoster Apr 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return _.extend({}, _.result(ItemsModel.prototype, "defaults"), {

Extra object needed so that the we don't overwrite the ItemsModel.prototype.defaults object with our Narrative defaults.

},

preRender: function() {
this.listenTo(Adapt, 'device:changed', this.reRender, this);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.listenTo(Adapt, {
    'device:changed': this.reRender,
    'device:resize', this.resizeControl,
    'notify:closed', this.closeNotify
});

^ if you feel like it?

},

prepareNarrativeModel: function() {
this.set('_component', 'narrative');
this.set('_wasHotgraphic', true);
this.set('originalBody', this.get('body'));
this.set('originalInstruction', this.get('instruction'));
this.set('_activeItem', (this.get('_activeItem') === -1) ? 0 : this.get('_activeItem'));

var activeItem = this.getActiveItemsIndexes()[0] || 0;
Copy link
Member

@oliverfoster oliverfoster Apr 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe on ItemsModel :

getFirstActiveItemIndex: function() {
    return this.getActiveItemsIndexes()[0];
},
getFirstActiveItem: function() {
    return this.model.getActiveItems()[0];
}

Seeing as this is used reasonably often in narrative (and probably hotgraphic, i haven't read it yet) I think it'll make these references easier.

this.model.set('_activeItem', stage);
nextStage = (nextStage + numberOfItems) % numberOfItems;
this.model.setItemAtIndexAsInactive(activeStage, false);
this.model.setItemAtIndexAsActive(nextStage, true);
Copy link
Member

@oliverfoster oliverfoster Apr 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you need the explicit true here? (and in onProgressClicked)

remove default trigger true falg for readability
assign listener to Adapt as object
this.set('_marginDir', 'right');
}
this.set('_itemCount', this.get('_items').length);

Copy link
Member

@oliverfoster oliverfoster Apr 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can your change this to defaults as with accordion:

defaults: function() {
    return _.extend({}, _.results(ItemsModel.prototype, "defaults"), {
        _marginDir: (Adapt.config.get('_defaultDirection') == 'rtl') ? 'left': 'right',
        _itemCount: this.getItemCount()
    });
}

Copy link
Contributor

@moloko moloko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested in IE11 and Firefox

@oliverfoster
Copy link
Member

please do not merge until @tomgreenfield comes back with review

@lc-thomasberger
Copy link
Member Author

close this one in favor for #179

@moloko moloko deleted the itemsModel branch June 26, 2018 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants