-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TemplateController w/o TemplateController :) #30
Comments
Released!
head
title simple
body
+demo(test='123')
template(name="demo")
div props:
= props.test
div
a.node(href="#") NEW
form
input(type="text" value-bind="fieldHead|throttle:500")
= state.fieldHead
input(type="text" value-bind="fieldBody|debounce:500")
= state.fieldBody
button(type="submit") SUBMIT
button#reset RESET
= state.submitMessage
= state.errorMessages
ul
+each node in nodes
li
a.node(href="#" data-node-id=node._id)
= node.fieldHead
| /
= node.fieldBody Template.demo.onCreated ->
@propsSchema new SimpleSchema(test: type: String)
@modelSchema Nodes.simpleSchema()
@states
nodeId: false
submitMessage: ''
@helpers
nodes: ->
Nodes.find()
@events
'click a.node': (e) ->
e.preventDefault()
@state.nodeId = $(e.target).data('node-id') or false
'submit form': (e) ->
e.preventDefault()
@viewDoc (error, doc) ->
return if error
# save data
if @state.nodeId
Nodes.update @state.nodeId, $set: doc,
=> @state.submitMessage = 'updated'
else
@state.nodeId = Nodes.insert doc,
=> @state.submitMessage = 'inserted'
# old school of declaration with context of Template.instance()
Template.demo.eventsByInstance
'click #reset': (e) ->
e.preventDefault()
@modelDoc false
@state.submitMessage = ''
Template.demo.onRendered ->
@modelMap() # magic here :)
@autorun =>
if @state.nodeId
@modelDoc Nodes.findOne @state.nodeId
else
@modelDoc false
@state.submitMessage = '' @Nodes = new (Mongo.Collection)('nodes')
@NodeSchema = new SimpleSchema
fieldHead:
type: String
label: 'My Head'
max: 3
defaultValue: '111'
fieldBody:
type: String
label: 'My Body'
min: 3
defaultValue: '777'
Nodes.attachSchema(NodeSchema) |
I want continue our coloboration! :) |
@comerc it's fine if you just use or create another MVVM package but this package intentionally tries not to tap into that water and stay as close to the official Blaze guide as possible, while supporting best practices and clean code. IMO splitting up view code into separate different styles and files or introducing the overloaded term "model" there is not at all best practices nor would i recommend this. |
Template2:
The text was updated successfully, but these errors were encountered: