Trapped-Processors.st 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. Smalltalk current createPackage: 'Trapped-Processors'!
  2. TrappedDataExpectingProcessor subclass: #TrappedProcessorDataAdhoc
  3. instanceVariableNames: 'toViewBlock'
  4. package: 'Trapped-Processors'!
  5. !TrappedProcessorDataAdhoc commentStamp!
  6. I put data into target via contents: in toView:!
  7. !TrappedProcessorDataAdhoc methodsFor: 'accessing'!
  8. toViewBlock: aBlock
  9. toViewBlock := aBlock
  10. ! !
  11. !TrappedProcessorDataAdhoc methodsFor: 'data transformation'!
  12. toView: aDataCarrier
  13. toViewBlock value: aDataCarrier
  14. ! !
  15. !TrappedProcessorDataAdhoc class methodsFor: 'instance creation'!
  16. newToView: aBlock
  17. ^self new
  18. toViewBlock: aBlock;
  19. yourself
  20. ! !
  21. TrappedProcessor subclass: #TrappedProcessorDescend
  22. instanceVariableNames: ''
  23. package: 'Trapped-Processors'!
  24. !TrappedProcessorDescend commentStamp!
  25. I intepret data-trap in descendants of my brush.!
  26. !TrappedProcessorDescend methodsFor: 'data transformation'!
  27. toView: aDataCarrier
  28. Trapped current injectToJQuery: aDataCarrier target asJQuery children
  29. ! !
  30. TrappedProcessor subclass: #TrappedProcessorGuardBase
  31. instanceVariableNames: 'guardPath'
  32. package: 'Trapped-Processors'!
  33. !TrappedProcessorGuardBase commentStamp!
  34. I serve as base class for brush-guarding processors.
  35. I cover instantiation and subclasses have to provide
  36. implementation of toVIew: that react appropriately to guard releasing.!
  37. !TrappedProcessorGuardBase methodsFor: 'accessing'!
  38. guardPath: anArray
  39. guardPath := anArray
  40. ! !
  41. !TrappedProcessorGuardBase methodsFor: 'data transformation'!
  42. toModel: aDataCarrier
  43. "stop"
  44. !
  45. toView: aDataCarrier
  46. self subclassResponsibility
  47. ! !
  48. !TrappedProcessorGuardBase class methodsFor: 'instance creation'!
  49. new: anArray
  50. ^ self new
  51. guardPath: anArray;
  52. yourself
  53. ! !
  54. TrappedProcessorGuardBase subclass: #TrappedProcessorGuardContents
  55. instanceVariableNames: ''
  56. package: 'Trapped-Processors'!
  57. !TrappedProcessorGuardContents commentStamp!
  58. I am used to guard contents of the brush I am installed on.
  59. I save the brush contents, then I observe guard expression in the model,
  60. and when it changes to nil or false, I delete the brush contents;
  61. on the other hand, when it changes to non-nil and non-false,
  62. I restore it from remembered state and interpret all contained
  63. data-trap attributes inside.!
  64. !TrappedProcessorGuardContents methodsFor: 'data transformation'!
  65. toView: aDataCarrier
  66. | frozen contents |
  67. frozen := aDataCarrier copy.
  68. contents := frozen target asJQuery contents detach.
  69. frozen target trapGuard: guardPath contents: [ :html |
  70. html root asJQuery append: contents.
  71. Trapped current injectToJQuery: html root asJQuery ]
  72. ! !
  73. TrappedProcessorGuardBase subclass: #TrappedProcessorGuardProc
  74. instanceVariableNames: ''
  75. package: 'Trapped-Processors'!
  76. !TrappedProcessorGuardProc commentStamp!
  77. I am used to guard contents filling process of the brush I am installed on.
  78. I observe guard expression in the model,
  79. and when it changes to nil or false, I delete the brush contents;
  80. on the other hand, when it changes to non-nil and non-false,
  81. I run the rest on the chain, which should be one-time
  82. that sets up the contents,!
  83. !TrappedProcessorGuardProc methodsFor: 'data transformation'!
  84. toView: aDataCarrier
  85. | frozen |
  86. frozen := aDataCarrier copy.
  87. frozen target trapGuard: guardPath contents: [ frozen copy proceed ]
  88. ! !
  89. TrappedDataExpectingProcessor subclass: #TrappedProcessorInputChecked
  90. instanceVariableNames: ''
  91. package: 'Trapped-Processors'!
  92. !TrappedProcessorInputChecked commentStamp!
  93. I bind to checkbox checked attribute.!
  94. !TrappedProcessorInputChecked methodsFor: 'data transformation'!
  95. toView: aDataCarrier
  96. aDataCarrier toTargetAttr: 'checked'
  97. ! !
  98. !TrappedProcessorInputChecked methodsFor: 'installation'!
  99. installToView: aDataCarrier toModel: anotherDataCarrier
  100. | brush |
  101. brush := aDataCarrier target.
  102. brush onChange: [ anotherDataCarrier copy value: (brush asJQuery attr: 'checked') notNil; proceed ]
  103. ! !
  104. TrappedDataExpectingProcessor subclass: #TrappedProcessorInputValue
  105. instanceVariableNames: ''
  106. package: 'Trapped-Processors'!
  107. !TrappedProcessorInputValue commentStamp!
  108. I bind to input value.!
  109. !TrappedProcessorInputValue methodsFor: 'data transformation'!
  110. toView: aDataCarrier
  111. aDataCarrier toTargetValue
  112. ! !
  113. !TrappedProcessorInputValue methodsFor: 'installation'!
  114. installToView: aDataCarrier toModel: anotherDataCarrier
  115. | brush |
  116. brush := aDataCarrier target.
  117. brush onChange: [ anotherDataCarrier copy value: brush asJQuery val; proceed ]
  118. ! !
  119. TrappedProcessor subclass: #TrappedProcessorLoopBase
  120. instanceVariableNames: ''
  121. package: 'Trapped-Processors'!
  122. !TrappedProcessorLoopBase commentStamp!
  123. I serve as base class for looping processors.
  124. I cover instantiation and subclasses have to provide
  125. implementation of toVIew: that loops appropriately.!
  126. !TrappedProcessorLoopBase methodsFor: 'data transformation'!
  127. toModel: aDataCarrier
  128. "stop"
  129. !
  130. toView: aDataCarrier
  131. self subclassResponsibility
  132. ! !
  133. TrappedProcessorLoopBase subclass: #TrappedProcessorLoopContents
  134. instanceVariableNames: ''
  135. package: 'Trapped-Processors'!
  136. !TrappedProcessorLoopContents commentStamp!
  137. I am used to loop over data and repeat the contents
  138. of the brush I am installed on.
  139. I save the brush contents, then I observe the data in the model,
  140. and when it changes, I loop over it
  141. and restore the contents from remembered state
  142. and interpret all contained data-trap attributes inside
  143. for each element, putting the result _after_ my brush.
  144. My brush itself should be as least visible as possible,
  145. as it only serve as a position flag (use for example
  146. noscript, ins or del).!
  147. !TrappedProcessorLoopContents methodsFor: 'data transformation'!
  148. toView: aDataCarrier
  149. | frozen contents |
  150. frozen := aDataCarrier copy.
  151. contents := frozen target asJQuery contents detach.
  152. frozen target trapIter: #() after: [ :html |
  153. html root asJQuery append: contents clone.
  154. Trapped current injectToJQuery: html root asJQuery ]
  155. ! !
  156. TrappedProcessorLoopBase subclass: #TrappedProcessorLoopProc
  157. instanceVariableNames: ''
  158. package: 'Trapped-Processors'!
  159. !TrappedProcessorLoopProc commentStamp!
  160. I am used to loop over data and repeat the contents filling process
  161. of the brush I am installed on.
  162. I observe the data in the model,
  163. and when it changes, I loop over it
  164. and run the rest of the processing chain
  165. for each element, putting the result _after_ my brush.
  166. My brush itself should be as least visible as possible,
  167. as it only serve as a position flag (use for example
  168. noscript, ins or del).!
  169. !TrappedProcessorLoopProc methodsFor: 'data transformation'!
  170. toView: aDataCarrier
  171. | frozen |
  172. frozen := aDataCarrier copy.
  173. frozen target trapIter: #() after: [ :html | frozen copy target: html root; proceed ]
  174. ! !
  175. TrappedProcessor subclass: #TrappedProcessorSignal
  176. instanceVariableNames: 'selector'
  177. package: 'Trapped-Processors'!
  178. !TrappedProcessorSignal commentStamp!
  179. Instead of writing data directly to model,
  180. I instead modify it by sending a message specified when instantiating me.!
  181. !TrappedProcessorSignal methodsFor: 'accessing'!
  182. selector: aString
  183. selector := aString
  184. ! !
  185. !TrappedProcessorSignal methodsFor: 'data transformation'!
  186. toModel: aDataCarrier
  187. aDataCarrier modifyTargetByPerforming: selector
  188. !
  189. toView: aDataCarrier
  190. "stop"
  191. ! !
  192. !TrappedProcessorSignal class methodsFor: 'instance creation'!
  193. new: aString
  194. ^self new
  195. selector: aString;
  196. yourself
  197. ! !
  198. TrappedProcessor subclass: #TrappedProcessorWhenClicked
  199. instanceVariableNames: ''
  200. package: 'Trapped-Processors'!
  201. !TrappedProcessorWhenClicked commentStamp!
  202. I bind to an element and send true to blackboard when clicked.!
  203. !TrappedProcessorWhenClicked methodsFor: 'installation'!
  204. installToView: aDataCarrier toModel: anotherDataCarrier
  205. aDataCarrier target onClick: [ anotherDataCarrier copy proceed. false ]
  206. ! !
  207. TrappedProcessor subclass: #TrappedProcessorWhenSubmitted
  208. instanceVariableNames: ''
  209. package: 'Trapped-Processors'!
  210. !TrappedProcessorWhenSubmitted commentStamp!
  211. I bind to a form and send true to blackboard when submitted.!
  212. !TrappedProcessorWhenSubmitted methodsFor: 'installation'!
  213. installToView: aDataCarrier toModel: anotherDataCarrier
  214. aDataCarrier target onSubmit: [ anotherDataCarrier copy proceed. false ]
  215. ! !
  216. TrappedProcessor subclass: #TrappedProcessorWidget
  217. instanceVariableNames: 'viewName'
  218. package: 'Trapped-Processors'!
  219. !TrappedProcessorWidget commentStamp!
  220. I insert a widget instance of the class specified when creating me.!
  221. !TrappedProcessorWidget methodsFor: 'accessing'!
  222. viewName: aString
  223. viewName := aString
  224. ! !
  225. !TrappedProcessorWidget methodsFor: 'data transformation'!
  226. toView: aDataCarrier
  227. aDataCarrier target with: (Smalltalk current at: viewName) new
  228. ! !
  229. !TrappedProcessorWidget class methodsFor: 'instance creation'!
  230. new: aString
  231. ^self new
  232. viewName: aString;
  233. yourself
  234. ! !
  235. !TrappedDataCarrier methodsFor: '*Trapped-Processors'!
  236. modifyTarget
  237. self target modify: [ self value ]
  238. !
  239. modifyTargetByPerforming: aString
  240. self target modify: [ :m | m perform: aString ]
  241. !
  242. toTargetAttr: aString
  243. self target asJQuery attr: aString put: (self value ifNotNil: [ :o | o value ] ifNil: [[]])
  244. !
  245. toTargetContents
  246. self target contents: self value
  247. !
  248. toTargetValue
  249. self target asJQuery val: (self value ifNotNil: [ :o | o value ] ifNil: [[]])
  250. ! !
  251. !TrappedProcessor class methodsFor: '*Trapped-Processors'!
  252. dataToView: aBlock
  253. ^TrappedProcessorDataAdhoc newToView: aBlock
  254. !
  255. guardContents: anArray
  256. ^TrappedProcessorGuardContents new: anArray
  257. !
  258. guardProc: anArray
  259. ^TrappedProcessorGuardProc new: anArray
  260. !
  261. inputChecked
  262. ^TrappedProcessorInputChecked new
  263. !
  264. inputValue
  265. ^TrappedProcessorInputValue new
  266. !
  267. loopContents
  268. ^TrappedProcessorLoopContents new
  269. !
  270. loopProc
  271. ^TrappedProcessorLoopProc new
  272. !
  273. path
  274. ^TrappedProcessorDescend new
  275. !
  276. signal: aString
  277. ^TrappedProcessorSignal new: aString
  278. !
  279. whenClicked
  280. ^TrappedProcessorWhenClicked new
  281. !
  282. whenSubmitted
  283. ^TrappedProcessorWhenSubmitted new
  284. !
  285. widget: aString
  286. ^TrappedProcessorWidget new: aString
  287. ! !