Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/client/templates/routes/Creation/Creation.html b/client/templates/routes/Creation/Creation.html
- index 2574d8c..ac52e7d 100644
- --- a/client/templates/routes/Creation/Creation.html
- +++ b/client/templates/routes/Creation/Creation.html
- @@ -5,6 +5,17 @@
- {{> CreationAddMenu creation=creation}}
- {{/if}}
- + {{#if ready }}
- +
- + <h1>IM READY </h1>
- +
- + {{else}}
- +
- + <h1 style="height: 1000px; width 1000px; background-color: red; color: white">
- + NOT READY
- + </h1>
- + {{/if}}
- +
- {{#Row align="center" classes="creation-stage"}}
- {{#Column sizes="small-12"}}
- diff --git a/client/templates/routes/Creation/Creation.js b/client/templates/routes/Creation/Creation.js
- index 5969ad1..755c53c 100644
- --- a/client/templates/routes/Creation/Creation.js
- +++ b/client/templates/routes/Creation/Creation.js
- @@ -2,10 +2,16 @@
- import { Template } from 'meteor/templating'
- import { FlowRouter } from 'meteor/kadira:flow-router'
- import Creations from '/imports/collections/creations'
- +import Subscriptions from '/imports/subscriptions/all'
- import './Creation.html'
- Template.Creation.helpers({
- + ready() {
- + return Subscriptions.creation.ready()
- + },
- creation() {
- - return Creations.findOne(FlowRouter.current().params._id)
- + let _id = FlowRouter.current().params._id
- + let creation = Creations.findOne(_id)
- + return creation
- }
- })
- diff --git a/imports/router/private.js b/imports/router/private.js
- index 88c7df5..722de14 100644
- --- a/imports/router/private.js
- +++ b/imports/router/private.js
- @@ -64,40 +64,46 @@ privateRoutes.route('/archives', {
- title: 'Creator'
- })
- -// TODO flow router group these creation routes so we dont sub/unsub when
- -// we move between them
- privateRoutes.route('/creation/:_id', {
- name: 'creation',
- - action(params) {
- - Subscriptions.creation.subscribe(params._id)
- - .then(() => {
- - BlazeLayout.render('Layout',
- - { content: 'Creation', header: 'HeaderCreation' })
- - })
- - .catch(err => {
- - BlazeLayout.render('LayoutPublic', {
- - content: 'Error',
- - data: { title: err.error, message: err.message }
- + action({_id}) {
- + // begin async subscription
- + Subscriptions.creation.subscribe(_id)
- + .catch(err => {
- + BlazeLayout.render('LayoutPublic', {
- + content: 'Error',
- + data: { title: err.error, message: err.message }
- + })
- })
- - })
- +
- + // immediately render - reactivity will update in-place when subscribed
- + BlazeLayout.render('Layout',
- + { content: 'Creation', header: 'HeaderCreation' })
- +
- },
- - triggersExit: [() => Subscriptions.creation.stop()]
- + triggersExit: [() => Subscriptions.creation.stop() /* XXX unless switching view/edit */]
- })
- privateRoutes.route('/creation/:_id/edit', {
- name: 'creation.edit',
- action(params) {
- + // begin async subscription
- Subscriptions.creation.subscribe(params._id)
- - .then(() => {
- - BlazeLayout.render('Layout',
- - { content: 'Creation', header: 'HeaderCreation' })
- - })
- - .catch(err => {
- - BlazeLayout.render('LayoutPublic',
- - { content: 'Error', title: err.error, message: err.message })
- - })
- + .catch(err => {
- + BlazeLayout.render('LayoutPublic',
- + {
- + content: 'Error',
- + title: err.error,
- + message: err.message
- + })
- + })
- +
- + // immediately render - reactivity will update in-place when subscribed
- + BlazeLayout.render('Layout',
- + { content: 'Creation', header: 'HeaderCreation' })
- +
- },
- - triggersExit: [() => Subscriptions.creation.stop()]
- + triggersExit: [() => Subscriptions.creation.stop() /* XXX unless switching view/edit */]
- })
- privateRoutes.route('/profile/:_id', {
- diff --git a/imports/subscriptions/all.js b/imports/subscriptions/all.js
- index 808236b..dd931aa 100644
- --- a/imports/subscriptions/all.js
- +++ b/imports/subscriptions/all.js
- @@ -4,6 +4,7 @@ import { _ } from 'meteor/underscore'
- // Returns a closure for starting and stopping subscriptions
- const makeSub = (name, ...curriedArgs) => {
- let handle = null
- + let promise = null
- return {
- ensureSubscribed: function (...args) {
- @@ -15,7 +16,7 @@ const makeSub = (name, ...curriedArgs) => {
- },
- // Usage: Subscriptions.name.subscribe(args).then(readyHandler, errorHandler)
- subscribe: (...args) => {
- - return new Promise((resolve, reject) => {
- + promise = new Promise((resolve, reject) => {
- handle = Meteor.subscribe(
- ...[name, ...curriedArgs, ...args],
- {
- @@ -28,10 +29,21 @@ const makeSub = (name, ...curriedArgs) => {
- }
- )
- })
- + return promise
- },
- stop: () => {
- handle.stop()
- handle = null // fahgeddaboutit
- + },
- + ensureStopped: () => {
- + !!(handle && handle.stop())
- + },
- + // an error to call if we haven't attempted to subscribe yet
- + ready: () => {
- + return handle.ready()
- + },
- + readyPromise: () => {
- + return promise
- }
- }
- }
- diff --git a/tests/unit/subscriptions/all.js b/tests/unit/subscriptions/all.js
- index effff5a..0193eb1 100644
- --- a/tests/unit/subscriptions/all.js
- +++ b/tests/unit/subscriptions/all.js
- @@ -10,9 +10,22 @@ describe('subscriptions/all', () => {
- it('rejects when an error received')
- })
- })
- + describe('#ensureSubscribed', () => {
- + it('safely calls subscribe() (does nothing if subscribed)')
- + })
- describe('#stop', () => {
- it('invokes stop on the underlying handle')
- })
- + describe('#ensureStopped', () => {
- + it('safely calls stop() - (does nothing if stopped)')
- + })
- + describe('#readyPromise', () => {
- + it('returns the most recent promise for readiness')
- + })
- + describe('#ready', () => {
- + it('returns ready() on the underlying handle')
- + it('is an error to call if we havent yet subscribed')
- + })
- })
- describe('#show()', () => {
- it('prints a table of all current DDP subscriptions')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement