From 8de45bab8d369e0c456afdd6d936f7a79996d10c Mon Sep 17 00:00:00 2001 From: "dr.dimitru" Date: Fri, 27 Jul 2018 01:55:58 +0300 Subject: [PATCH] v3.1.3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 🗑 Get rid of `underscore` package - 👷‍♂️ Update auto-tests - 📦 Update NPM and Atmosphere dependencies - 🤝 Compatibility with `meteor@1.7.0.3` --- .versions | 87 +++++++++++++++++++---------------------- flow-router-title.js | 85 ++++++++++++++++++++++++++++++++-------- package.js | 6 +-- tests/group-reactive.js | 21 +++++++--- 4 files changed, 126 insertions(+), 73 deletions(-) diff --git a/.versions b/.versions index 0ace47d..74ffba1 100644 --- a/.versions +++ b/.versions @@ -1,58 +1,51 @@ allow-deny@1.1.0 -babel-compiler@6.24.7 -babel-runtime@1.1.1 -base64@1.0.10 +babel-compiler@7.1.1 +babel-runtime@1.2.2 +base64@1.0.11 binary-heap@1.0.10 -blaze@2.3.2 -blaze-tools@1.0.10 -boilerplate-generator@1.3.0 -caching-compiler@1.1.9 -caching-html-compiler@1.0.6 -callback-hook@1.0.10 -check@1.2.5 +boilerplate-generator@1.5.0 +callback-hook@1.1.0 +check@1.3.1 ddp@1.4.0 -ddp-client@2.2.0 -ddp-common@1.3.0 -ddp-server@2.1.0 -deps@1.0.12 -diff-sequence@1.0.7 -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 +dynamic-import@0.4.1 +ecmascript@0.11.1 +ecmascript-runtime@0.7.0 +ecmascript-runtime-client@0.7.1 +ecmascript-runtime-server@0.7.0 ejson@1.1.0 geojson-utils@1.0.10 -html-tools@1.0.11 -htmljs@1.0.11 -id-map@1.0.9 -jquery@1.11.10 -local-test:ostrio:flow-router-title@3.1.2 -logging@1.1.19 -meteor@1.8.0 -minimongo@1.4.0 -modules@0.11.0 -modules-runtime@0.9.0 -mongo@1.3.1 +http@1.4.1 +id-map@1.1.0 +local-test:ostrio:flow-router-title@3.1.3 +logging@1.1.20 +meteor@1.9.0 +minimongo@1.4.4 +modern-browsers@0.1.2 +modules@0.12.0 +modules-runtime@0.10.0 +mongo@1.5.0 mongo-dev-server@1.1.0 -mongo-id@1.0.6 -npm-mongo@2.2.33 -observe-sequence@1.0.16 -ordered-dict@1.0.9 -ostrio:flow-router-extra@3.4.3 -ostrio:flow-router-title@3.1.2 -promise@0.10.0 -random@1.0.10 +mongo-id@1.0.7 +npm-mongo@3.0.7 +ordered-dict@1.1.0 +ostrio:flow-router-extra@3.5.1 +ostrio:flow-router-title@3.1.3 +promise@0.11.1 +random@1.1.0 reactive-dict@1.2.0 reactive-var@1.0.11 -retry@1.0.9 -routepolicy@1.0.12 +reload@1.2.0 +retry@1.1.0 +routepolicy@1.0.13 session@1.1.7 -spacebars@1.0.15 -spacebars-compiler@1.1.2 -templating@1.2.13 -templating-tools@1.1.1 -tinytest@1.0.12 -tracker@1.1.3 +socket-stream-client@0.2.2 +tinytest@1.1.0 +tracker@1.2.0 underscore@1.0.10 -webapp@1.4.0 +url@1.2.0 +webapp@1.6.0 webapp-hashing@1.0.9 diff --git a/flow-router-title.js b/flow-router-title.js index 6362918..32fafe7 100644 --- a/flow-router-title.js +++ b/flow-router-title.js @@ -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; @@ -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; } } @@ -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); } @@ -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; } @@ -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 ''; @@ -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; } } @@ -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); } @@ -134,7 +185,7 @@ export class FlowRouterTitle { } set(str) { - if (_.isString(str)) { + if (helpers.isString(str)) { this.title.set(str); return true; } @@ -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; diff --git a/package.js b/package.js index 0d2172f..e8890a8 100644 --- a/package.js +++ b/package.js @@ -1,6 +1,6 @@ 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' @@ -8,12 +8,12 @@ Package.describe({ 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'); diff --git a/tests/group-reactive.js b/tests/group-reactive.js index a3b486f..6843c09 100644 --- a/tests/group-reactive.js +++ b/tests/group-reactive.js @@ -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() { @@ -86,7 +95,7 @@ nestedReactiveGroup.route('/witTitle', { action() { Meteor.setTimeout(() => { nestedGroupReactiveVarPagelvl2Title.set(nestedGroupReactiveStrPagelvl2TitleNew); - }, 3000); + }, 256); } }); @@ -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) { @@ -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) { @@ -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) { @@ -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); });