-
Notifications
You must be signed in to change notification settings - Fork 39
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
Items model #170
Conversation
removed unused functions
updated required Framework version
js/narrativeModel.js
Outdated
defaults: function() { | ||
return _.extend({ | ||
_activeItem: 0 | ||
}, ItemsModel.prototype.defaults); |
There was a problem hiding this comment.
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;
js/narrativeModel.js
Outdated
var NarrativeModel = ItemsModel.extend({ | ||
|
||
defaults: function() { | ||
return _.extend({ |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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
js/narrativeModel.js
Outdated
}, | ||
|
||
checkCompletionStatus: function() { | ||
ItemsModel.prototype.checkCompletionStatus.apply(this, arguments); |
There was a problem hiding this comment.
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
js/narrativeModel.js
Outdated
@@ -6,9 +6,9 @@ define([ | |||
var NarrativeModel = ItemsModel.extend({ | |||
|
|||
defaults: function() { | |||
return _.extend({ | |||
return _.extend(_.result(ItemsModel.prototype, "defaults"), { |
There was a problem hiding this comment.
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.
added empty object to extend funciton for defaults
js/narrativeView.js
Outdated
}, | ||
|
||
preRender: function() { | ||
this.listenTo(Adapt, 'device:changed', this.reRender, this); |
There was a problem hiding this comment.
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?
js/narrativeModel.js
Outdated
}, | ||
|
||
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; |
There was a problem hiding this comment.
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.
js/narrativeView.js
Outdated
this.model.set('_activeItem', stage); | ||
nextStage = (nextStage + numberOfItems) % numberOfItems; | ||
this.model.setItemAtIndexAsInactive(activeStage, false); | ||
this.model.setItemAtIndexAsActive(nextStage, true); |
There was a problem hiding this comment.
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
js/narrativeModel.js
Outdated
this.set('_marginDir', 'right'); | ||
} | ||
this.set('_itemCount', this.get('_items').length); | ||
|
There was a problem hiding this comment.
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()
});
}
There was a problem hiding this 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
please do not merge until @tomgreenfield comes back with review |
close this one in favor for #179 |
_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.