Skip to content

Commit

Permalink
v3.1.3
Browse files Browse the repository at this point in the history
 - πŸ—‘ Get rid of `underscore` package
 - πŸ‘·β€β™‚οΈ Update auto-tests
 - πŸ“¦ Update NPM and Atmosphere dependencies
 - 🀝 Compatibility with `[email protected]`
  • Loading branch information
dr-dimitru committed Jul 26, 2018
1 parent d4cc3d5 commit 8de45ba
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 73 deletions.
87 changes: 40 additions & 47 deletions .versions
Original file line number Diff line number Diff line change
@@ -1,58 +1,51 @@
[email protected]
babel-compiler@6.24.7
babel-runtime@1.1.1
[email protected].10
babel-compiler@7.1.1
babel-runtime@1.2.2
[email protected].11
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
ddp-client@2.2.0
ddp-common@1.3.0
ddp-server@2.1.0
deps@1.0.12
[email protected]
ecmascript@0.9.0
ecmascript-runtime@0.5.0
ecmascript-runtime-client@0.5.0
ecmascript-runtime-server@0.5.0
ddp-client@2.3.2
ddp-common@1.4.0
ddp-server@2.2.0
diff-sequence@1.1.0
[email protected]
ecmascript@0.11.1
ecmascript-runtime@0.7.0
ecmascript-runtime-client@0.7.1
ecmascript-runtime-server@0.7.0
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
local-test:ostrio:[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
local-test:ostrio:[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
ostrio:[email protected]
ostrio:[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
ostrio:[email protected]
ostrio:[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
85 changes: 68 additions & 17 deletions flow-router-title.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,58 @@
import { _ } from 'meteor/underscore';
import { Tracker } from 'meteor/tracker';
import { ReactiveVar } from 'meteor/reactive-var';

const helpers = {
isObject(obj) {
if (this.isArray(obj) || this.isFunction(obj)) {
return false;
}
return obj === Object(obj);
},
isArray(obj) {
return Array.isArray(obj);
},
isFunction(obj) {
return typeof obj === 'function' || false;
},
isEmpty(obj) {
if (this.isDate(obj)) {
return false;
}
if (this.isObject(obj)) {
return !Object.keys(obj).length;
}
if (this.isArray(obj) || this.isString(obj)) {
return !obj.length;
}
return false;
},
has(_obj, path) {
let obj = _obj;
if (!this.isObject(obj)) {
return false;
}
if (!this.isArray(path)) {
return this.isObject(obj) && Object.prototype.hasOwnProperty.call(obj, path);
}

const length = path.length;
for (let i = 0; i < length; i++) {
if (!Object.prototype.hasOwnProperty.call(obj, path[i])) {
return false;
}
obj = obj[path[i]];
}
return !!length;
}
};

const _helpers = ['String', 'Date'];
for (let i = 0; i < _helpers.length; i++) {
helpers['is' + _helpers[i]] = function (obj) {
return Object.prototype.toString.call(obj) === '[object ' + _helpers[i] + ']';
};
}

export class FlowRouterTitle {
constructor(router) {
const self = this;
Expand All @@ -27,9 +78,9 @@ export class FlowRouterTitle {
result = cb(result);
}

if (_.isString(result)) {
if (helpers.isString(result)) {
self.title.set(result);
if (context && context.context && _.isObject(context.context)) {
if (context && context.context && helpers.isObject(context.context)) {
context.context.title = result;
}
}
Expand All @@ -40,7 +91,7 @@ export class FlowRouterTitle {
};

this.titleExitHandler = () => {
for (var i = computations.length - 1; i >= 0; i--) {
for (let i = computations.length - 1; i >= 0; i--) {
computations[i].stop();
computations.splice(i, 1);
}
Expand All @@ -49,13 +100,13 @@ export class FlowRouterTitle {
this.titleHandler = (context, redirect, stop, data) => {
let _title;
let defaultTitle = null;
const _context = _.extend(context, { query: context.queryParams });
const _context = Object.assign({}, context, { query: context.queryParams });
const _arguments = [context.params, context.queryParams, data];
let _groupTitlePrefix = this._getParentPrefix(((this.router._current && this.router._current.route && this.router._current.route.group) ? this.router._current.route.group : void 0), _context, _arguments);

if (this.router.globals.length) {
for (let j = 0; j < this.router.globals.length; j++) {
if (_.isObject(this.router.globals[j]) && _.has(this.router.globals[j], 'title')) {
if (helpers.isObject(this.router.globals[j]) && helpers.has(this.router.globals[j], 'title')) {
defaultTitle = this.router.globals[j].title;
break;
}
Expand All @@ -67,9 +118,9 @@ export class FlowRouterTitle {
let _groupTitle = (context.route.group.options && context.route.group.options.title) ? context.route.group.options.title : void 0;

const applyRouteTitle = (__routeTitle) => {
if (_.isFunction(__routeTitle)) {
if (helpers.isFunction(__routeTitle)) {
return __routeTitle.apply(_context, _arguments);
} else if (_.isString(__routeTitle)) {
} else if (helpers.isString(__routeTitle)) {
return __routeTitle;
}
return '';
Expand All @@ -88,26 +139,26 @@ export class FlowRouterTitle {
return __title;
};

if (_.isFunction(_routeTitle)) {
if (helpers.isFunction(_routeTitle)) {
this._reactivate(_routeTitle, _context, context, _arguments, applyGroupTitle);
return;
}

if (_.isFunction(_groupTitle)) {
if (helpers.isFunction(_groupTitle)) {
this._reactivate(_groupTitle, _context, context, _arguments, applyGroupTitle);
return;
}
_title = applyGroupTitle(_groupTitle);
} else {
_title = (context.route.options && context.route.options.title) ? context.route.options.title : (defaultTitle || hardCodedTitle);
if (_.isFunction(_title)) {
if (helpers.isFunction(_title)) {
this._reactivate(_title, _context, context, _arguments);
}
}

if (_.isString(_title)) {
if (helpers.isString(_title)) {
self.title.set(_title);
if (context && context.context && _.isObject(context.context)) {
if (context && context.context && helpers.isObject(context.context)) {
context.context.title = _title;
}
}
Expand All @@ -124,8 +175,8 @@ export class FlowRouterTitle {
};
_context.route.options.title = (self.router.notFound && self.router.notFound.title) ? self.router.notFound.title : void 0;

if (!_.isEmpty(self.router._current)) {
self.titleHandler(_.extend(self.router._current, _context));
if (!helpers.isEmpty(self.router._current)) {
self.titleHandler(Object.assign({}, self.router._current, _context));
} else {
self.titleHandler(_context);
}
Expand All @@ -134,7 +185,7 @@ export class FlowRouterTitle {
}

set(str) {
if (_.isString(str)) {
if (helpers.isString(str)) {
this.title.set(str);
return true;
}
Expand All @@ -148,7 +199,7 @@ export class FlowRouterTitle {
if (group.options && group.options.titlePrefix) {
if ((_context.route.options && _context.route.options.title && i === 1) || i !== 1) {
let _gt = group.options.titlePrefix;
if (_.isFunction(_gt)) {
if (helpers.isFunction(_gt)) {
_gt = _gt.apply(_context, _arguments);
}
prefix += _gt;
Expand Down
6 changes: 3 additions & 3 deletions package.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
Package.describe({
name: 'ostrio:flow-router-title',
version: '3.1.2',
version: '3.1.3',
summary: 'Change document.title (page title) on the fly within flow-router',
git: 'https://github.com/VeliovGroup/Meteor-flow-router-title',
documentation: 'README.md'
});

Package.onUse(function (api) {
api.versionsFrom('1.4');
api.use(['underscore', 'ecmascript', 'reactive-var', 'tracker'], 'client');
api.use(['ecmascript', 'reactive-var', 'tracker'], 'client');
api.mainModule('flow-router-title.js', 'client');
});

Package.onTest(function(api) {
api.use(['tinytest', 'ecmascript', 'random', 'session', 'reactive-var', 'tracker', 'ostrio:flow-router-extra', 'ostrio:flow-router-title'], 'client');
api.use(['tinytest', 'ecmascript', 'random', 'session', 'reactive-var', 'tracker', 'ostrio:flow-router-extra@3.5.1', 'ostrio:flow-router-title'], 'client');
api.addFiles('tests/init.js', 'client');
api.addFiles('tests/common.js', 'client');
api.addFiles('tests/group.js', 'client');
Expand Down
21 changes: 15 additions & 6 deletions tests/group-reactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ const groupReactiveVarTitle = new ReactiveVar(groupReactiveStrTitle);
const groupReactiveStrPrefix = 'Reactive Group > ';
const groupReactiveVarPrefix = new ReactiveVar(groupReactiveStrPrefix);


Meteor.startup(() => {
try {
FlowRouter.go('/');
} catch (e) {
// we're good
}
});

const groupReactive = FlowRouter.group({
prefix: '/group-reactive',
title() {
Expand Down Expand Up @@ -86,7 +95,7 @@ nestedReactiveGroup.route('/witTitle', {
action() {
Meteor.setTimeout(() => {
nestedGroupReactiveVarPagelvl2Title.set(nestedGroupReactiveStrPagelvl2TitleNew);
}, 3000);
}, 256);
}
});

Expand All @@ -98,7 +107,7 @@ Tinytest.addAsync('Group - Reactive - level 1 - no route title', function (test,
test.equal(document.title, groupReactiveStrTitleNew);
next();
}, 512);
}, 100);
}, 10);
});

Tinytest.addAsync('Group - Reactive - level 1 - with route title', function (test, next) {
Expand All @@ -109,7 +118,7 @@ Tinytest.addAsync('Group - Reactive - level 1 - with route title', function (tes
test.equal(document.title, groupReactiveStrPrefix + groupReactiveStrPage2TitleNew);
next();
}, 512);
}, 100);
}, 10);
});

Tinytest.addAsync('Group - Reactive - level 2 - no route title', function (test, next) {
Expand All @@ -120,7 +129,7 @@ Tinytest.addAsync('Group - Reactive - level 2 - no route title', function (test,
test.equal(document.title, groupReactiveStrPrefix + nestedGroupReactiveStrTitleNew);
next();
}, 512);
}, 100);
}, 10);
});

Tinytest.addAsync('Group - Reactive - level 2 - with route title', function (test, next) {
Expand All @@ -130,6 +139,6 @@ Tinytest.addAsync('Group - Reactive - level 2 - with route title', function (tes
Meteor.setTimeout(() => {
test.equal(document.title, groupReactiveStrPrefix + nestedGroupReactiveStrPrefix + nestedGroupReactiveStrPagelvl2TitleNew, 'after reactive update');
next();
}, 3512);
}, 100);
}, 512);
}, 10);
});

0 comments on commit 8de45ba

Please sign in to comment.