Slowly modernizing the tutorial.

Fixed autoreload and Makefile to be more, um, relative.
This commit is contained in:
Elf M. Sternberg 2016-04-15 15:43:05 -07:00
parent 2b09593ec7
commit fdf2b4367d
3 changed files with 14 additions and 10 deletions

View File

@ -1,4 +1,4 @@
.PHONY: setup store .PHONY: setup store serve
NOTANGLE= notangle NOTANGLE= notangle
NOWEAVE= noweave NOWEAVE= noweave
@ -12,6 +12,11 @@ LIBS:= htdocs/lib/underscore.js htdocs/lib/jquery.js htdocs/lib/backbone.js
all: htdocs/index.html htdocs/store.js htdocs/jsonstore.css htdocs/data/items.json all: htdocs/index.html htdocs/store.js htdocs/jsonstore.css htdocs/data/items.json
@if [ ! -e "./htdocs/lib" ]; then echo "Please do 'make setup' before continuing"; fi @if [ ! -e "./htdocs/lib" ]; then echo "Please do 'make setup' before continuing"; fi
serve: all
$(COFFEE) ./bin/autoreload
store: all
htdocs/lib: htdocs/lib:
mkdir -p htdocs/lib mkdir -p htdocs/lib

View File

@ -1,4 +1,4 @@
#!/usr/bin/env coffee #!/bin/env coffee
fs = require 'fs' fs = require 'fs'
Inotify = require('inotify').Inotify Inotify = require('inotify').Inotify
@ -13,7 +13,7 @@ monitor = new Inotify()
reBuild = -> reBuild = ->
maker = spawn 'make', ['store'] maker = spawn 'make', ['store']
make.stdout.on 'data', spew maker.stdout.on 'data', spew
monitor.addWatch monitor.addWatch
path: "./src/backbonestore.nw" path: "./src/backbonestore.nw"

View File

@ -391,7 +391,7 @@ class ProductListView extends _BaseView
@collection.bind 'reset', _.bind(@render, @) @collection.bind 'reset', _.bind(@render, @)
render: () -> render: () ->
@el.html(_.template(@template, {'products': @collection.toJSON()})) @el.html(_.template(@template)({'products': @collection.toJSON()}))
@ @
@ @
@ -442,7 +442,6 @@ class ProductView extends _BaseView
initialize: (options) -> initialize: (options) ->
_BaseView.prototype.initialize.apply @, [options] _BaseView.prototype.initialize.apply @, [options]
@itemcollection = options.itemcollection @itemcollection = options.itemcollection
@item = @itemcollection.getOrCreateItemForProduct @model
@ @
%$ %$
@ -491,11 +490,10 @@ helps clarify what it is you're looking for.
<<product detail view>>= <<product detail view>>=
update: (e) -> update: (e) ->
e.preventDefault() e.preventDefault()
@item.update parseInt(@$('.uqf').val()) @itemcollection.update @model, parseInt(@$('.uqf').val())
updateOnEnter: (e) -> updateOnEnter: (e) ->
if (e.keyCode == 13) @update(e) if e.keyCode == 13
@update e
@ @
%$ %$
@ -504,7 +502,7 @@ The render is straightforward:
<<product detail view>>= <<product detail view>>=
render: () -> render: () ->
@el.html(_.template(@template, @model.toJSON())); @el.html(_.template(@template)(@model.toJSON()));
@ @
@ @
@ -562,9 +560,10 @@ show that it did changed:
<<cart widget>>= <<cart widget>>=
render: () -> render: () ->
tel = @el.html _.template @template, tel = @el.html _.template(@template)({
'count': @collection.getTotalCount() 'count': @collection.getTotalCount()
'cost': @collection.getTotalCost() 'cost': @collection.getTotalCost()
})
tel.animate({paddingTop: '30px'}).animate({paddingTop: '10px'}) tel.animate({paddingTop: '30px'}).animate({paddingTop: '10px'})
@ @