Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.52 KB | None | 0 0
  1. diff --git a/client/templates/routes/Creation/Creation.html b/client/templates/routes/Creation/Creation.html
  2. index 2574d8c..ac52e7d 100644
  3. --- a/client/templates/routes/Creation/Creation.html
  4. +++ b/client/templates/routes/Creation/Creation.html
  5. @@ -5,6 +5,17 @@
  6. {{> CreationAddMenu creation=creation}}
  7. {{/if}}
  8.  
  9. + {{#if ready }}
  10. +
  11. + <h1>IM READY </h1>
  12. +
  13. + {{else}}
  14. +
  15. + <h1 style="height: 1000px; width 1000px; background-color: red; color: white">
  16. + NOT READY
  17. + </h1>
  18. + {{/if}}
  19. +
  20. {{#Row align="center" classes="creation-stage"}}
  21.  
  22. {{#Column sizes="small-12"}}
  23. diff --git a/client/templates/routes/Creation/Creation.js b/client/templates/routes/Creation/Creation.js
  24. index 5969ad1..755c53c 100644
  25. --- a/client/templates/routes/Creation/Creation.js
  26. +++ b/client/templates/routes/Creation/Creation.js
  27. @@ -2,10 +2,16 @@
  28. import { Template } from 'meteor/templating'
  29. import { FlowRouter } from 'meteor/kadira:flow-router'
  30. import Creations from '/imports/collections/creations'
  31. +import Subscriptions from '/imports/subscriptions/all'
  32.  
  33. import './Creation.html'
  34. Template.Creation.helpers({
  35. + ready() {
  36. + return Subscriptions.creation.ready()
  37. + },
  38. creation() {
  39. - return Creations.findOne(FlowRouter.current().params._id)
  40. + let _id = FlowRouter.current().params._id
  41. + let creation = Creations.findOne(_id)
  42. + return creation
  43. }
  44. })
  45. diff --git a/imports/router/private.js b/imports/router/private.js
  46. index 88c7df5..722de14 100644
  47. --- a/imports/router/private.js
  48. +++ b/imports/router/private.js
  49. @@ -64,40 +64,46 @@ privateRoutes.route('/archives', {
  50. title: 'Creator'
  51. })
  52.  
  53. -// TODO flow router group these creation routes so we dont sub/unsub when
  54. -// we move between them
  55. privateRoutes.route('/creation/:_id', {
  56. name: 'creation',
  57. - action(params) {
  58. - Subscriptions.creation.subscribe(params._id)
  59. - .then(() => {
  60. - BlazeLayout.render('Layout',
  61. - { content: 'Creation', header: 'HeaderCreation' })
  62. - })
  63. - .catch(err => {
  64. - BlazeLayout.render('LayoutPublic', {
  65. - content: 'Error',
  66. - data: { title: err.error, message: err.message }
  67. + action({_id}) {
  68. + // begin async subscription
  69. + Subscriptions.creation.subscribe(_id)
  70. + .catch(err => {
  71. + BlazeLayout.render('LayoutPublic', {
  72. + content: 'Error',
  73. + data: { title: err.error, message: err.message }
  74. + })
  75. })
  76. - })
  77. +
  78. + // immediately render - reactivity will update in-place when subscribed
  79. + BlazeLayout.render('Layout',
  80. + { content: 'Creation', header: 'HeaderCreation' })
  81. +
  82. },
  83. - triggersExit: [() => Subscriptions.creation.stop()]
  84. + triggersExit: [() => Subscriptions.creation.stop() /* XXX unless switching view/edit */]
  85. })
  86.  
  87. privateRoutes.route('/creation/:_id/edit', {
  88. name: 'creation.edit',
  89. action(params) {
  90. + // begin async subscription
  91. Subscriptions.creation.subscribe(params._id)
  92. - .then(() => {
  93. - BlazeLayout.render('Layout',
  94. - { content: 'Creation', header: 'HeaderCreation' })
  95. - })
  96. - .catch(err => {
  97. - BlazeLayout.render('LayoutPublic',
  98. - { content: 'Error', title: err.error, message: err.message })
  99. - })
  100. + .catch(err => {
  101. + BlazeLayout.render('LayoutPublic',
  102. + {
  103. + content: 'Error',
  104. + title: err.error,
  105. + message: err.message
  106. + })
  107. + })
  108. +
  109. + // immediately render - reactivity will update in-place when subscribed
  110. + BlazeLayout.render('Layout',
  111. + { content: 'Creation', header: 'HeaderCreation' })
  112. +
  113. },
  114. - triggersExit: [() => Subscriptions.creation.stop()]
  115. + triggersExit: [() => Subscriptions.creation.stop() /* XXX unless switching view/edit */]
  116. })
  117.  
  118. privateRoutes.route('/profile/:_id', {
  119. diff --git a/imports/subscriptions/all.js b/imports/subscriptions/all.js
  120. index 808236b..dd931aa 100644
  121. --- a/imports/subscriptions/all.js
  122. +++ b/imports/subscriptions/all.js
  123. @@ -4,6 +4,7 @@ import { _ } from 'meteor/underscore'
  124. // Returns a closure for starting and stopping subscriptions
  125. const makeSub = (name, ...curriedArgs) => {
  126. let handle = null
  127. + let promise = null
  128.  
  129. return {
  130. ensureSubscribed: function (...args) {
  131. @@ -15,7 +16,7 @@ const makeSub = (name, ...curriedArgs) => {
  132. },
  133. // Usage: Subscriptions.name.subscribe(args).then(readyHandler, errorHandler)
  134. subscribe: (...args) => {
  135. - return new Promise((resolve, reject) => {
  136. + promise = new Promise((resolve, reject) => {
  137. handle = Meteor.subscribe(
  138. ...[name, ...curriedArgs, ...args],
  139. {
  140. @@ -28,10 +29,21 @@ const makeSub = (name, ...curriedArgs) => {
  141. }
  142. )
  143. })
  144. + return promise
  145. },
  146. stop: () => {
  147. handle.stop()
  148. handle = null // fahgeddaboutit
  149. + },
  150. + ensureStopped: () => {
  151. + !!(handle && handle.stop())
  152. + },
  153. + // an error to call if we haven't attempted to subscribe yet
  154. + ready: () => {
  155. + return handle.ready()
  156. + },
  157. + readyPromise: () => {
  158. + return promise
  159. }
  160. }
  161. }
  162. diff --git a/tests/unit/subscriptions/all.js b/tests/unit/subscriptions/all.js
  163. index effff5a..0193eb1 100644
  164. --- a/tests/unit/subscriptions/all.js
  165. +++ b/tests/unit/subscriptions/all.js
  166. @@ -10,9 +10,22 @@ describe('subscriptions/all', () => {
  167. it('rejects when an error received')
  168. })
  169. })
  170. + describe('#ensureSubscribed', () => {
  171. + it('safely calls subscribe() (does nothing if subscribed)')
  172. + })
  173. describe('#stop', () => {
  174. it('invokes stop on the underlying handle')
  175. })
  176. + describe('#ensureStopped', () => {
  177. + it('safely calls stop() - (does nothing if stopped)')
  178. + })
  179. + describe('#readyPromise', () => {
  180. + it('returns the most recent promise for readiness')
  181. + })
  182. + describe('#ready', () => {
  183. + it('returns ready() on the underlying handle')
  184. + it('is an error to call if we havent yet subscribed')
  185. + })
  186. })
  187. describe('#show()', () => {
  188. it('prints a table of all current DDP subscriptions')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement