From 58641fd48cf8e677eb3ab0456d992e4b7562507b Mon Sep 17 00:00:00 2001 From: Stefan Geneshky Date: Mon, 23 Nov 2015 14:39:56 -0800 Subject: [PATCH] Update rivets and its test --- rivets/rivets-tests.ts | 34 +++++++++------- rivets/rivets.d.ts | 88 ++++++++++++++++++++++++++++-------------- 2 files changed, 79 insertions(+), 43 deletions(-) diff --git a/rivets/rivets-tests.ts b/rivets/rivets-tests.ts index fec282046..f23772094 100644 --- a/rivets/rivets-tests.ts +++ b/rivets/rivets-tests.ts @@ -1,18 +1,22 @@ /// -Rivets.configure({ - // Attribute prefix in templates - prefix: 'rv', - // Preload templates with initial data on bind - preloadData: true, - // Root sightglass interface for keypaths - rootInterface: '.', - // Template delimiters for text bindings - templateDelimiters: ['[[', ']]'], - // Augment the event handler of the on-* binder - handler: function(target:any, event:any, binding:any) { - this.call(target, event, binding.view.models) - } - }) +rivets.configure({ + // Attribute prefix in templates + prefix: 'rv', + // Preload templates with initial data on bind + preloadData: true, + // Root sightglass interface for keypaths + rootInterface: '.', + // Template delimiters for text bindings + templateDelimiters: ['[[', ']]'], + // Augment the event handler of the on-* binder + handler: function(target:any, event:any, binding:any) { + this.call(target, event, binding.view.models) + } +}); + var t = {test: ["hello", "one", "two"]} -Rivets.bind(document.getElementById("para1"), t) \ No newline at end of file +var opts = {bar: "foo"}; +rivets.bind(document.getElementById("para1"), t); +rivets.bind(document.getElementById("para1"), t, opts); +rivets.bind([document.getElementById("para1"), document.getElementById("para2")], t); diff --git a/rivets/rivets.d.ts b/rivets/rivets.d.ts index 2b04653ec..de3ebf47b 100644 --- a/rivets/rivets.d.ts +++ b/rivets/rivets.d.ts @@ -3,33 +3,65 @@ // Definitions by: Trevor Baron // Definitions: https://github.com/borisyankov/DefinitelyTyped -interface FinchStatic { - configure(options?: { - /** - * Attribute prefix in templates - */ - prefix?: string; - /** - * Preload templates with initial data on bind - */ - preloadData?: boolean; - /** - * Root sightglass interface for keypaths - */ - rootInterface?: string; - /** - * Template delimiters for text bindings - */ - templateDelimiters?: Array - /** - * Augment the event handler of the on-* binder - */ - handler?: Function; - }):void; - bind(element:any, template:any):void; +/// + +declare module Rivets { + + interface View { + build(): void; + bind(): void; + unbind(): void; + } + + interface Rivets { + // Global binders. + binders: Object; + + // Global components. + components: Object; + + // Global formatters. + formatters: Object; + + // Global sightglass adapters. + adapters: Object; + + // Default attribute prefix. + prefix: string; + + // Default template delimiters. + templateDelimiters: Array; + + // Default sightglass root interface. + rootInterface: string; + + // Preload data by default. + preloadData: boolean; + + handler(context: any, ev: Event, biding: any): void; + + configure(options?: { + + // Attribute prefix in templates + prefix?: string; + + //Preload templates with initial data on bind + preloadData?: boolean; + + //Root sightglass interface for keypaths + rootInterface?: string; + + // Template delimiters for text bindings + templateDelimiters?: Array + + // Augment the event handler of the on-* binder + handler?: Function; + }): void; + + bind(element: HTMLElement, models: Object, options?: Object): View; + bind(element: JQuery, models: Object, options?: Object): View; + bind(element: Array, models: Object, options?: Object): View; + } } -declare var Rivets: FinchStatic; -declare module "rivets" { - export = Rivets; -} +declare var rivets: Rivets.Rivets;