OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library template_binding.src.binding_delegate; | |
6 | |
7 import 'dart:html'; | |
8 import 'package:template_binding/template_binding.dart' show TemplateInstance; | |
9 | |
10 /** | |
11 * Template Bindings native features enables a wide-range of use cases, | |
12 * but (by design) don't attempt to implement a wide array of specialized | |
13 * behaviors. | |
14 * | |
15 * Enabling these features is a matter of implementing and registering a | |
16 * BindingDelegate. A binding delegate is an object which contains one or more | |
17 * delegation functions which implement specialized behavior. This object is | |
18 * registered via [TemplateBindExtension.bindingDelegate]: | |
19 * | |
20 * HTML: | |
21 * <template bind> | |
22 * {{ What!Ever('crazy')->thing^^^I+Want(data) }} | |
23 * </template> | |
24 * | |
25 * Dart: | |
26 * class MySyntax extends BindingDelegate { | |
27 * prepareBinding(path, name, node) { | |
28 * // The magic happens here! | |
29 * } | |
30 * } | |
31 * ... | |
32 * templateBind(query('template')) | |
33 * ..bindingDelegate = new MySyntax() | |
34 * ..model = new MyModel(); | |
35 * | |
36 * | |
37 * See | |
38 * <http://www.polymer-project.org/platform/template.html#binding-delegate-api> | |
39 * for more information about the binding delegate. | |
40 */ | |
41 // TODO(jmesserly): need better api docs here. The link above seems out of date. | |
42 abstract class BindingDelegate { | |
43 /** | |
44 * Prepares a binding. This is called immediately after parsing a mustache | |
45 * token with `{{ path }}` in the context of the [node] and the property named | |
46 * [name]. This should return a function that will be passed the actual | |
47 * node and model, and either returns null or an object with a `value` | |
48 * property. This allows the syntax to reinterpret the model for each binding. | |
49 */ | |
50 PrepareBindingFunction prepareBinding(String path, String name, Node node) | |
51 => null; | |
52 | |
53 /** | |
54 * Returns a function that can optionally replace the model that will be | |
55 * passed to [TemplateBindExtension.createInstance]. This can be used to | |
56 * implement syntax such as `<template repeat="{{ item in items }}">` by | |
57 * ensuring that the returned model has the "item" name available. | |
58 */ | |
59 PrepareInstanceModelFunction prepareInstanceModel(Element template) => null; | |
60 | |
61 /** | |
62 * Returns a function that will be called whenever the position of an item | |
63 * inside this template changes. | |
64 * this template. | |
Siggi Cherem (dart-lang)
2013/10/29 22:49:49
remove line
Jennifer Messerly
2013/10/29 23:07:19
Done.
| |
65 */ | |
66 PrepareInstancePositionChangedFunction prepareInstancePositionChanged( | |
67 Element template) => null; | |
68 } | |
69 | |
70 // TODO(jmesserly): removed the name parameter as it is redundant. | |
71 // https://github.com/Polymer/TemplateBinding/issues/146 | |
72 typedef PrepareBindingFunction(model, Node node); | |
73 | |
74 typedef PrepareInstanceModelFunction(model); | |
75 | |
76 typedef PrepareInstancePositionChangedFunction(TemplateInstance instance, | |
77 int index); | |
OLD | NEW |