Skip to content

Commit

Permalink
MDL-63064 block_starredcourses: change events to use pubsub
Browse files Browse the repository at this point in the history
  • Loading branch information
lameze committed Oct 31, 2018
1 parent d5d7699 commit 07fdb5a
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 13 deletions.
2 changes: 1 addition & 1 deletion blocks/myoverview/amd/build/view.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions blocks/myoverview/amd/src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@ define(
'jquery',
'block_myoverview/repository',
'core/paged_content_factory',
'core/pubsub',
'core/custom_interaction_events',
'core/notification',
'core/templates',
'core_course/events'
],
function(
$,
Repository,
PagedContentFactory,
PubSub,
CustomEvents,
Notification,
Templates
Templates,
CourseEvents
) {

var SELECTORS = {
Expand Down Expand Up @@ -197,9 +201,7 @@ function(

setCourseFavouriteState(courseId, true).then(function(success) {
if (success) {
// Trigger a JS event so the starred courses block can refresh the list of courses.
$('body').trigger('myoverview-events:course_starred', [courseId]);

PubSub.publish(CourseEvents.favourited);
removeAction.removeClass('hidden');
addAction.addClass('hidden');
showFavouriteIcon(root, courseId);
Expand All @@ -222,7 +224,7 @@ function(

setCourseFavouriteState(courseId, false).then(function(success) {
if (success) {
$('body').trigger('myoverview-events:course_unstarred', [courseId]);
PubSub.publish(CourseEvents.unfavorited);
removeAction.addClass('hidden');
addAction.removeClass('hidden');
hideFavouriteIcon(root, courseId);
Expand Down
2 changes: 1 addition & 1 deletion blocks/starredcourses/amd/build/main.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions blocks/starredcourses/amd/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@ define(
'core/notification',
'block_starredcourses/repository',
'core/paged_content_factory',
'core/templates'
'core/pubsub',
'core/templates',
'core_course/events'
],
function(
$,
Notification,
Repository,
PagedContentFactory,
Templates
PubSub,
Templates,
CourseEvents
) {

var SELECTORS = {
Expand Down Expand Up @@ -111,13 +115,11 @@ function(
* @param {Number} userid The user id.
*/
var registerEventListeners = function(root, userid) {
var body = $('body');

body.on('myoverview-events:course_starred', function() {
PubSub.subscribe(CourseEvents.favourited, function() {
reloadContent(root, userid);
});

body.on('myoverview-events:course_unstarred', function() {
PubSub.subscribe(CourseEvents.unfavorited, function() {
reloadContent(root, userid);
});
};
Expand Down
1 change: 1 addition & 0 deletions course/amd/build/events.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
define([],function(){return{favourited:"core_course:favourited",unfavorited:"core_course:unfavorited"}});
29 changes: 29 additions & 0 deletions course/amd/src/events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Contain the events the course component can trigger.
*
* @module core_course/events
* @package core_course
* @copyright 2018 Simey Lameze <simey@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define([], function() {
return {
favourited: 'core_course:favourited',
unfavorited: 'core_course:unfavorited',
};
});

0 comments on commit 07fdb5a

Please sign in to comment.