Commit Graph

53 Commits

Author SHA1 Message Date
David Greenspan
c21f49c6e3 Back-compat for template-internal API calls 2014-08-29 16:20:42 -07:00
David Greenspan
8345de74e9 Merge branch 'devel' into blaze-templates
Conflicts:
	docs/.meteor/versions
	docs/client/api.html
	docs/client/docs.js
	packages/blaze/builtins.js
	packages/blaze/materializer.js
	packages/blaze/render_tests.js
	packages/blaze/view.js
	packages/livedata/package.js
	packages/minimongo/package.js
	packages/reactive-var/reactive-var.js
	packages/standard-app-packages/package.js
	packages/templating/templating.js
	packages/test-helpers/reactivevar.js
	packages/test-in-browser/package.js
	packages/ui/package.js
2014-08-27 22:34:21 -07:00
Sashko Stubailo
41910019e1 Renamed Deps to Tracker in all packages 2014-08-27 20:05:22 -07:00
David Greenspan
f5883827ae Make UI.ReactiveVar public 2014-08-18 17:34:35 -07:00
David Greenspan
f35ce02196 Rename to view._render, onView{Created,Destroyed} 2014-08-13 14:33:05 -07:00
David Greenspan
307b9a9504 Make more Blaze calls private
Put underscores before:

ReactiveVar, InOuterTemplateScope, EventSupport, reportException,
wrapCatchingExceptions, DOMMaterializer, and HTMLJSExpander
2014-08-11 14:38:46 -07:00
David Greenspan
7ca944e665 UI.render/toHTML, TemplateWith, Blaze.toText
Move Spacebars.TemplateWith to Blaze._TemplateWith.  It is the official
way to give a template data, after all, but it’s a little too weird to
make public.  Use it in Blaze.renderWithData, even though it doesn’t
seem like it would make a difference.

Unify UI.render/renderWithData with Blaze.render, and add
toHTMLWithData.  Publicly, they take a Template or a View.
The View must be unrendered, of course.  If given a Template,
constructView will be called.  Privately, they take any HTMLJS
extended to be allowed to contain Templates and Views, except
null or undefined, or a function returning extended HTMLJS.
The “data” argument may be a function or a not, as in UI.With
(and unlike the old public UI.renderWithData).

Make Blaze.toText private (Blaze._toText).
2014-08-11 14:24:07 -07:00
David Greenspan
22d4c48188 Rename Template.__create__, __define__, and others
* `Template.__create__` is now `new Template`
* `Template = Blaze.Template`
* `Template` is a constructor function
* `Template.foo instanceof Template` (but keep `Blaze.isTemplate`)
* No more `Blaze.runTemplate` (use `template.constructView`)
* `constructView` instead of `__makeView`
* template objects have `__kind` and `__render`
* No `__viewName`, `__templateName`
* `Template.__body__` is now `Template._body_` (and renamed methods)
* No `Template.__lookup__`, instead `(name in Template) && (Template[name] instance of Template)`
* `Template.__define__` replaced by `Template.__assign(name, template)`
2014-08-06 16:05:27 -07:00
David Greenspan
75c30ef073 Fix scope of UI.contentBlock argument
Eric Dobbertin’s bug
2014-07-28 12:23:54 -07:00
David Greenspan
4c8223c6f4 Reduce helper re-running when #with changes case
Yay.  Some interesting Deps thinking here too.
2014-07-03 16:53:13 -07:00
David Greenspan
e4ca96af57 Fix “stop” reactivity
Destroy members of a DOMRange immediately on invalidation of the last render, not waiting for re-run.  Provide DOMRange#destroyMembers.

Don’t call view.autorun from view.render() in builtins, and enforce it.

Remove dead code “onstop” from DOMRange.
2014-07-01 10:18:56 -07:00
David Greenspan
b2d620955b Blaze.isTemplate, Blaze.runTemplate 2014-06-30 16:37:13 -07:00
David Greenspan
d6bd5654ce tinytest sort of works 2014-06-30 16:11:18 -07:00
David Greenspan
ab4bb8f993 Get rid of 3s/OLDSTYLE, start to exclude old code 2014-06-30 15:45:12 -07:00
David Greenspan
aacb940591 Seem to have a working Each view 2014-06-27 21:45:01 -07:00
David Greenspan
a4481cb6f5 Capitalize something 2014-06-26 19:22:28 -07:00
David Greenspan
42c790e797 Fix #with; set current view on autorun 2014-06-26 18:58:36 -07:00
David Greenspan
85b80d3266 Implement lookup, more builtins
Move lookup to templates, not views!
2014-06-26 18:23:31 -07:00
David Greenspan
3480c67077 Make inclusions work in Blaze.View world 2014-06-26 10:25:57 -07:00
David Greenspan
d16e94945e Implement “move” in DOMRange, prepare for UI hooks 2014-06-23 15:58:07 -07:00
David Greenspan
87123cc63a Kill spacebars-common package
Now that Spacebars and SpacebarsCompiler are different symbols, it’s not necessary.
2014-06-23 15:13:00 -07:00
David Greenspan
0940e4dde8 Spacebars.include2 -> Spacebars.include 2014-06-21 18:21:50 -07:00
David Greenspan
99d6545d70 Spacebars.With2 -> Spacebars.With 2014-06-21 18:20:36 -07:00
David Greenspan
5c23ec2e36 Merge remote-tracking branch 'origin/devel' into blaze-refactor 2014-06-09 19:58:19 -07:00
Emily Stark
f6cb154770 Make sure autoruns for {{#with}} get cleaned up.
Related to #2145, #2023, #2031.
2014-06-09 19:13:23 -07:00
David Greenspan
4e8472e970 Proper reactivity for calculated templates 2014-06-09 16:35:24 -07:00
David Greenspan
9108c5debd Match devel’s behavior for inclusion arg context 2014-06-09 14:02:46 -07:00
David Greenspan
adcf6c853c Allow null in inclusion to match devel 2014-06-09 12:32:32 -07:00
Emily Stark
ba0770a908 Merge remote-tracking branch 'origin/devel' into blaze-refactor
Conflicts:
	packages/html-tools/tokenize.js
	packages/spacebars-compiler/package.js
	packages/spacebars-compiler/spacebars-compiler.js
	packages/spacebars-tests/template_tests.html
	packages/spacebars-tests/template_tests.js
	packages/spacebars/package.js
	packages/spacebars/spacebars-runtime.js
	packages/ui/domrange.js
	packages/ui/render_tests.js
2014-06-06 14:05:44 -07:00
David Greenspan
51858c10d0 Make UI.safeEquals the default Blaze.Var behavior 2014-06-06 12:27:48 -07:00
Emily Stark
4b6d3b2681 Reshuffle packages to allow ui to depend on ui-dynamic-template.
Remove the spacebars-compiler -> spacebars and spacebars-compiler -> ui
dependencies. With those dependencies, ui cannot depend on
ui-dynamic-template, because ui-dynamic-template depends on templating,
whose build plugin depends on spacebars-compiler, who depends on
spacebars who depends on ui.

spacebars-compiler doesn't actually need to depend on ui or spacebars;
it only needs to depend on spacebars to add things to the `Spacebars`
namespace, which this commit does by factoring out the Spacebars export
into a separate `spacebars-common` package.
2014-05-28 14:37:12 -07:00
David Greenspan
86570b2218 Implement events and helpers with “old this”
Tinytest runs now!  A bunch of tests fail though.
2014-05-14 17:59:37 -07:00
David Greenspan
38f5932b81 Basic template inclusions work
Events are not attached.

contentBlock doesn’t work.
2014-05-13 18:02:24 -07:00
David Greenspan
71a432d049 Make #each support {{else}} 2014-05-06 12:24:34 -07:00
David Greenspan
bed3d1ed3d Basic #each works
Needs {{else}} case.  Also {{.}} doesn't work yet
2014-05-06 08:59:47 -07:00
David Greenspan
1669783a86 #with 2014-05-05 20:19:00 -07:00
Avital Oliver
95aaa99312 Fix {{#with}} over a data context that is mutated
In `Spacebars.With` we embox the data context. This commit makes
that emboxing happen modulo `safeEquals`. So now if you
{{#with}} over a helper that returns an object, any time
that helper gets invalidated we re-run the computations in the block.

Fixes #2046 (though notably that example mutates the data context
from within a helper, which could lead to other types of unintended
behavior; it's probably in this particular example -- the data context
just gets added properties)
2014-04-19 00:29:34 -07:00
David Greenspan
480016ea8b Fix #with 2014-03-23 09:53:53 -07:00
Avital Oliver
c2d985c235 Handlebars.SafeString -> Spacebars.SafeString 2014-03-22 00:35:26 -07:00
David Greenspan
09b9b4adba Tower of hacks to get shark deps right
The implementation is getting really, really ugly.  Just want to get to correctness.

We now stop autoruns not just when started from `materialize` but also `toHTML`, `toText`, and `evaluate`, which is important for HTML attributes.  Reactive regions inside attributes aren't individually autorun; the design is that their dependencies will cause the entire attribute updater to be invalidated and re-run.  In other words, HTML.toText doesn't have internal re-runs but it does register dependencies on the current computation.  In fact, however, the presence of emboxedValues means that there *are* autoruns that need to be stopped, even in toText and evaluate.

The hack where we define a `.materialized()` callback for the benefit of UI.With falls short, because toText et al. don't call it.  The current workaround is yet worse hacks in htmljs (stopWithLater).

Finally, the fact that UI.If, UI.Unless, and Spacebars.include return reactive closures that close over emboxedValues is a problem when those same closures are reused in recalculating attributes.  The intent was that recalculating attributes should tear down any boxes internal to the attribute calculation and start fresh, but when we reuse closures that close over boxes, we are reusing boxes, and if those boxes have been stopped we lose correctness.  The ugly hack to get this to work for now is to have the boxes in If, Unless and include not be per reactive closure but per currentComputation, i.e. per autorun.  Since toText et al. don't normally autorun reactive closures, we add an autorun so that they get their own Computation objects.  This hack is supported by UI.namedEmboxValue and callReactiveFunction.

The good news is that the right answer is buried in here somewhere.
2014-03-21 03:54:28 -07:00
David Greenspan
c910fce4c6 Make emboxValue dumb; explicitly stop autoruns 2014-03-20 09:39:13 -07:00
Avital Oliver
b97d9e143a Eliminate Deps.isolateValue
Unfortunately, using it always led to reactive functions
firing twice. Instead, we now use emboxValue in the two
cases we originally had Deps.isolateValue.
2014-03-17 15:09:52 -07:00
David Greenspan
951b07c7c0 Support Spacebars.SafeString
...not just Handlebars.SafeString.

Test that helpers can depend on `instanceof Spacebars.kw` to detect options hash.
2014-02-05 23:06:18 -08:00
David Greenspan
04138ce206 Fix data context and .. in {{> content}}
according to today's proposal (i.e. it's as if {{> content}} were invoked at the invocation site of the template that uses {{> content}}, as far as scopes are concerned).

Messy implementation with not enough comments.  But there's a test.
2014-02-03 17:32:14 -08:00
David Greenspan
135aefbdee Fix broken newargs semantics
All tests pass (except one which is a todo on shark).

If `{{> foo bar}}` is to desugar into `{{#with bar}}{{> foo}}{{/with}}`, there needs to be an explicit block in the generated code in which `self.lookup("foo")` binds the correct data context (`bar`).  So we now generate a UI.With rather than trying to call it from Spacebars.include.  This simplifies Spacebars.include, which is nice.

Define `lookupTemplate` because `self.lookup(.., {template: true})` pretty-prints bigly.
2014-02-02 12:26:48 -08:00
David Greenspan
45b5885def Move re-render's isolateValue to UI; fix bugs
* Use isolateValue around `foo` in `{{> foo}}` as well as `{{#foo}}` (i.e. whether or not there's a content block)
* Make UI.With always embox its argument; this is achieved by moving embox/isolateValue from Spacebars into UI.  As a side effected, all reactive closures now use isolateValue, so we avoid re-rendering in a few more cases.
* Avoid calling data argument of `{{#with someHelper}}` twice ever instead of once ever (when helper isn't invalidated)
2014-02-01 19:58:13 -08:00
David Greenspan
a538501efe Fix bug in newargs; fix some tests 2014-01-29 18:32:47 -08:00
David Greenspan
5038c63d08 Merge shark, including shark-isolate-helpers work 2014-01-27 15:21:23 -08:00
David Greenspan
599ac16632 Treat null/undefined/false attributes as absent
So, in HTML, the following are equivalent, and both mean that a checkbox is checked, because the `checked` attribute is present:

- `<input type="checkbox" checked>`
- `<input type="checkbox" checked="">`

We can't mess with that.  On the other hand, in Spacebars before this commit, the following would *also* result in the checkbox being checked, regardless of whether `foo` evaluates to null, undefined, false, or the empty string:

- `<input type="checkbox" checked={{foo}}>`
- `<input type="checkbox" checked="{{foo}}">`

With this commit, the checkbox will NOT be checked if `foo` evaluates to null, undefined, or false.

To achieve this:

- In HTMLjs, an attribute is considered absent if its value is "nully" after being fully evaluated (i.e. after expanding functions and components via HTML.evaluateDynamicAttributes / HTML.evaluate).  A nully value is one consisting of null, undefined, an empty array, or an array of those things.  `false` is not nully and renders as "false".  An empty string is not nully, and will "prop open" an attribute that would otherwise collapse into absence.

- Spacebars.mustache converts null, undefined, and false to null.  So if you use {{foo}} anywhere in a template and foo evaluates to "false", that gets to converted to a null in HTMLjs (which is ignored).  (true is rendered as "true".)

- When parsing HTML, an attribute that consists of *no tokens* becomes an empty string in the HTMLjs, which props open the attribute (unlike null or an empty array).  (Since comment tokens are stripped during tokenization, if there are only comments in an attribute value that counts as no tokens.)
2014-01-27 14:44:19 -08:00
Avital Oliver
72a5d4282c Correct helper return value isolation
- When helpers return SafeStrings, compare their underlying
  strings.
- When helpers return objects (such as for dynamic attributes),
  never isolate. The objects may have been mutated directly.
  AttributeHandler ends up only affecting real changes.
2014-01-26 11:52:26 -08:00