├── .gitignore
├── README.md
├── state.json
├── .vscode
└── settings.json
├── src
├── store
│ └── index.ts
├── infrastructure
│ └── index.ts
├── app.ts
├── components
│ └── colorCanvas.ts
├── actions
│ └── index.ts
├── index.html
├── viewmodels
│ └── mainViewModel.ts
└── reducers
│ └── index.ts
├── tsconfig.json
├── typings
├── tsd.d.ts
├── object-assign
│ └── object-assign.d.ts
├── redux
│ └── redux.d.ts
├── mocha
│ └── mocha.d.ts
├── chai
│ └── chai.d.ts
└── knockout
│ └── knockout.d.ts
├── tsd.json
├── package.json
├── webpack.config.js
├── tests
├── actions
│ └── index.spec.ts
└── reducers
│ └── index.spec.ts
└── dist
├── index.html
└── app.js
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Redux with knockoutjs
2 |
3 | Small proof of concept application
--------------------------------------------------------------------------------
/state.json:
--------------------------------------------------------------------------------
1 | {
2 | "width":200,
3 | "height":200,
4 | "color":"yellow",
5 | "errors":[]
6 | }
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | // Place your settings in this file to overwrite default and user settings.
2 | {
3 | "typescript.tsdk": "./node_modules/typescript/lib"
4 | }
--------------------------------------------------------------------------------
/src/store/index.ts:
--------------------------------------------------------------------------------
1 | ///
2 | import { createStore } from "redux";
3 | import colorReducers from '../reducers/index';
4 |
5 | const store = createStore(colorReducers)
6 |
7 | export default store;
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "ES6"
4 | },
5 | "files":[
6 | "typings/tsd.d.ts"
7 | ],
8 | "exclude":[
9 | "node_modules",
10 | "typings",
11 | "src/declarations/app.d.ts"
12 | ]
13 | }
--------------------------------------------------------------------------------
/typings/tsd.d.ts:
--------------------------------------------------------------------------------
1 |
2 | ///
3 | ///
4 | ///
5 | ///
6 | ///
7 |
--------------------------------------------------------------------------------
/src/infrastructure/index.ts:
--------------------------------------------------------------------------------
1 | export interface IApplicationState {
2 | width?: number;
3 | height?: number;
4 | color?: string;
5 | errors?:Array;
6 | }
7 |
8 | export enum ActionTypes {
9 | CHANGE_COLOR,
10 | CHANGE_WIDTH,
11 | CHANGE_HEIGHT
12 | }
13 |
14 | export interface IAction {
15 | type: ActionTypes,
16 | payload?: any
17 | }
--------------------------------------------------------------------------------
/typings/object-assign/object-assign.d.ts:
--------------------------------------------------------------------------------
1 | // Type definitions for object-assign 4.0.1
2 | // Project: https://github.com/sindresorhus/object-assign
3 | // Definitions by: Christopher Brown
4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped
5 |
6 | declare module "object-assign" {
7 | export default function objectAssign(target: any, ...sources: any[]): any;
8 | }
9 |
--------------------------------------------------------------------------------
/src/app.ts:
--------------------------------------------------------------------------------
1 | ///
2 | import {mainViewModel} from "./viewmodels/mainViewModel";
3 | import ko from "knockout";
4 | import {component, componentName} from "./components/colorCanvas";
5 |
6 | (function(){
7 | window.onload = () => {
8 | ko.components.register(componentName, component);
9 |
10 | var node:HTMLElement = document.getElementById("app");
11 | ko.applyBindings(mainViewModel, node);
12 | };
13 | })();
--------------------------------------------------------------------------------
/src/components/colorCanvas.ts:
--------------------------------------------------------------------------------
1 | ///
2 | import ko from "knockout";
3 |
4 | export const componentName = "color-canvas";
5 | export const component = {
6 | viewModel:function(params){
7 | this.style = ko.pureComputed(() => {
8 | return {
9 | "display":"block",
10 | "backgroundColor":params.color(),
11 | "width":params.width(),
12 | "height":params.height()
13 | };
14 | });
15 | },
16 | template:`
17 |
18 | `
19 | };
--------------------------------------------------------------------------------
/src/actions/index.ts:
--------------------------------------------------------------------------------
1 | import {IAction, ActionTypes} from "../infrastructure/index";
2 |
3 | function changeWidth(width:number):IAction{
4 | return {
5 | type:ActionTypes.CHANGE_WIDTH,
6 | payload:width
7 | }
8 | }
9 |
10 | function changeHeight(height:number):IAction{
11 | return {
12 | type:ActionTypes.CHANGE_HEIGHT,
13 | payload:height
14 | };
15 | }
16 |
17 | function changeColor(color:string):IAction {
18 | return {
19 | type:ActionTypes.CHANGE_COLOR,
20 | payload:color
21 | }
22 | }
23 |
24 | export default {
25 | changeWidth,
26 | changeHeight,
27 | changeColor
28 | }
--------------------------------------------------------------------------------
/tsd.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "v4",
3 | "repo": "borisyankov/DefinitelyTyped",
4 | "ref": "master",
5 | "path": "typings",
6 | "bundle": "typings/tsd.d.ts",
7 | "installed": {
8 | "chai/chai.d.ts": {
9 | "commit": "fb2b3b1e068c9ff7d8f9b0851c08d37d96c95c38"
10 | },
11 | "mocha/mocha.d.ts": {
12 | "commit": "fb2b3b1e068c9ff7d8f9b0851c08d37d96c95c38"
13 | },
14 | "es6-collections/es6-collections.d.ts": {
15 | "commit": "fb2b3b1e068c9ff7d8f9b0851c08d37d96c95c38"
16 | },
17 | "object-assign/object-assign.d.ts": {
18 | "commit": "fb2b3b1e068c9ff7d8f9b0851c08d37d96c95c38"
19 | },
20 | "knockout/knockout.d.ts": {
21 | "commit": "fb2b3b1e068c9ff7d8f9b0851c08d37d96c95c38"
22 | },
23 | "redux/redux.d.ts": {
24 | "commit": "fb2b3b1e068c9ff7d8f9b0851c08d37d96c95c38"
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "redux-knockoutjs",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "webpack.config.js",
6 | "directories": {
7 | "test": "tests"
8 | },
9 | "scripts": {
10 | "pretests":"webpack",
11 | "test": "mocha \"./tests/tests.js\"",
12 | "watch":"webpack --watch",
13 | "test:watch":"mocha \"./tests/tests.js\" --watch",
14 | "server":"webpack-dev-server --inline --watch --content-base dist",
15 | "compile":"webpack"
16 | },
17 | "author": "",
18 | "license": "ISC",
19 | "devDependencies": {
20 | "babel-core": "^6.2.1",
21 | "babel-loader": "^6.2.0",
22 | "babel-preset-es2015": "^6.1.18",
23 | "chai": "^3.4.1",
24 | "glob": "^6.0.1",
25 | "html-webpack-plugin": "^1.7.0",
26 | "mocha": "^2.3.4",
27 | "ts-loader": "^0.7.2",
28 | "typescript": "^1.8.0-dev.20151129",
29 | "webpack": "^1.12.9",
30 | "webpack-dev-server": "^1.14.0"
31 | },
32 | "dependencies": {
33 | "knockout": "^3.4.0",
34 | "object-assign": "^4.0.1",
35 | "redux": "^3.0.4"
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/webpack.config.js:
--------------------------------------------------------------------------------
1 | var webpack = require("webpack");
2 | var HtmlWebpackPlugin = require("html-webpack-plugin");
3 | var glob = require("glob");
4 |
5 | module.exports = [{
6 | entry:{
7 | "app":"./src/app.ts",
8 | vendor: ["knockout","object-assign","redux"]
9 | },
10 | output: {
11 | path: __dirname + "/dist",
12 | filename: "[name].js"
13 | },
14 | module: {
15 | loaders: [
16 | // note that babel-loader is configured to run after ts-loader
17 | {
18 | test: /\.ts(x?)$/,
19 | loader: "babel-loader?presets[]=es2015!ts-loader",
20 | exclude:"node_modules"
21 | }
22 | ]
23 | },
24 | resolve: {
25 | extensions: ["", ".webpack.js", ".web.js", ".ts", ".js"]
26 | },
27 | plugins: [
28 | new webpack.optimize.CommonsChunkPlugin(/* chunkName= */"vendor", /* filename= */"vendor.bundle.js"),
29 | new HtmlWebpackPlugin({
30 | title:"Knockout and Redux",
31 | template:"./src/index.html"
32 | })
33 | ]
34 | },
35 | {
36 | entry:glob.sync("./tests/**/*.ts"),
37 | output: {
38 | path: __dirname + "/tests",
39 | filename: "tests.js"
40 | },
41 | module: {
42 | loaders: [
43 | // note that babel-loader is configured to run after ts-loader
44 | {
45 | test: /\.ts(x?)$/,
46 | loader: "babel-loader?presets[]=es2015!ts-loader",
47 | exclude:"node_modules"
48 | }
49 | ]
50 | },
51 | resolve: {
52 | extensions: ["", ".webpack.js", ".web.js", ".ts", ".js"]
53 | }
54 | }]
--------------------------------------------------------------------------------
/tests/actions/index.spec.ts:
--------------------------------------------------------------------------------
1 | ///
2 | import {default as actions} from "../../src/actions/index";
3 | import {IAction, ActionTypes} from "../../src/infrastructure/index";
4 | import {assert} from "chai";
5 |
6 | describe("action", () => {
7 | describe("changeWidth", () => {
8 | let action:IAction;
9 | beforeEach(() => {
10 | action = actions.changeWidth(200);
11 | });
12 |
13 | it("should return action with type CHANGE_WIDTH", () => {
14 | assert.equal(action.type, ActionTypes.CHANGE_WIDTH);
15 | });
16 |
17 | it("should return action with payload 200", () => {
18 | assert.equal(action.payload, 200);
19 | });
20 | })
21 |
22 | describe("changeHeight", () => {
23 | let action:IAction;
24 | beforeEach(() => {
25 | action = actions.changeHeight(150);
26 | });
27 |
28 | it("should return action with type CHANGE_HEIGHT", () =>{
29 | assert.equal(action.type, ActionTypes.CHANGE_HEIGHT);
30 | });
31 |
32 | it("should return action with payload 150", () => {
33 | assert.equal(action.payload, 150);
34 | });
35 | });
36 |
37 | describe("changeColor", () => {
38 | let action:IAction;
39 | beforeEach(() => {
40 | action = actions.changeColor("red");
41 | });
42 |
43 | it("should return action with type CHANGE_COLOR", () => {
44 | assert.equal(action.type, ActionTypes.CHANGE_COLOR);
45 | })
46 |
47 | it("should return action with payload red", () => {
48 | assert.equal(action.payload, "red");
49 | });
50 | })
51 | })
--------------------------------------------------------------------------------
/typings/redux/redux.d.ts:
--------------------------------------------------------------------------------
1 | // Type definitions for Redux v1.0.0
2 | // Project: https://github.com/rackt/redux
3 | // Definitions by: William Buchwalter , Vincent Prouillet
4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped
5 |
6 | declare module Redux {
7 |
8 | interface ActionCreator extends Function {
9 | (...args: any[]): any;
10 | }
11 |
12 | interface Reducer extends Function {
13 | (state: any, action: any): any;
14 | }
15 |
16 | interface Dispatch extends Function {
17 | (action: any): any;
18 | }
19 |
20 | interface StoreMethods {
21 | dispatch: Dispatch;
22 | getState(): any;
23 | }
24 |
25 |
26 | interface MiddlewareArg {
27 | dispatch: Dispatch;
28 | getState: Function;
29 | }
30 |
31 | interface Middleware extends Function {
32 | (obj: MiddlewareArg): Function;
33 | }
34 |
35 | class Store {
36 | getReducer(): Reducer;
37 | replaceReducer(nextReducer: Reducer): void;
38 | dispatch(action: any): any;
39 | getState(): any;
40 | subscribe(listener: Function): Function;
41 | }
42 |
43 | function createStore(reducer: Reducer, initialState?: any): Store;
44 | function bindActionCreators(actionCreators: T, dispatch: Dispatch): T;
45 | function combineReducers(reducers: any): Reducer;
46 | function applyMiddleware(...middlewares: Middleware[]): Function;
47 | function compose(...functions: Function[]): T;
48 | }
49 |
50 | declare module "redux" {
51 | export = Redux;
52 | }
53 |
--------------------------------------------------------------------------------
/dist/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Knockout and Redux
7 |
9 |
15 |
16 |
17 |
18 |
19 |
Knockout and Redux
20 |
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Knockout and Redux
7 |
9 |
15 |
16 |
17 |
18 |
19 |
Knockout and Redux
20 |
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/src/viewmodels/mainViewModel.ts:
--------------------------------------------------------------------------------
1 | ///
2 | import ko from "knockout";
3 | import store from "../store/index";
4 | import {IApplicationState, IAction} from "../infrastructure/index";
5 | import {default as actions} from "../actions/index";
6 |
7 | class MainViewModel {
8 | private applicationState:KnockoutObservable;
9 | color:KnockoutComputed;
10 | height:KnockoutComputed;
11 | width:KnockoutComputed;
12 | statePrint:KnockoutComputed;
13 | errors:KnockoutComputed>;
14 | hasErrors:KnockoutComputed;
15 |
16 | private unsubscribe:Function;
17 |
18 | constructor(){
19 | this.applicationState = ko.observable(this.getState());
20 |
21 | this.unsubscribe = store.subscribe(() => {
22 | console.info("store changed");
23 | this.applicationState(this.getState());
24 | });
25 |
26 | this.color = ko.pureComputed(() => this.applicationState().color);
27 | this.height = ko.pureComputed(() => `${this.applicationState().height}px`);
28 | this.width = ko.pureComputed(() => `${this.applicationState().width}px`);
29 | this.statePrint = ko.pureComputed(() => ko.toJSON(this.applicationState()));
30 | this.errors = ko.pureComputed>(() => this.applicationState().errors);
31 | this.hasErrors = ko.pureComputed(() => {return (this.errors() && this.errors().length > 0)});
32 | }
33 |
34 | updateWidth(data:any, e:Event){
35 | this.updateDimension(e, actions.changeWidth);
36 | }
37 |
38 | updateHeight(data:any, e:Event){
39 | this.updateDimension(e, actions.changeHeight);
40 | }
41 |
42 | private updateDimension(e:Event,actionCreator:Function):void{
43 | var value = this.getValueAsInt(e.target);
44 | if(value){
45 | this.dispatch(actionCreator(value));
46 | }
47 | }
48 |
49 | private getValueAsInt(input:HTMLInputElement):number{
50 | return input.value;
51 | }
52 |
53 | updateColor(data:any, e:Event){
54 | this.dispatch(actions.changeColor((e.target).value));
55 | }
56 |
57 | private getState():IApplicationState{
58 | return store.getState() || {color:"", width:"", height:"", errors:[]};
59 | }
60 |
61 | private dispatch(action:IAction){
62 | return store.dispatch(action);
63 | }
64 | }
65 |
66 | export var mainViewModel = new MainViewModel();
67 |
--------------------------------------------------------------------------------
/src/reducers/index.ts:
--------------------------------------------------------------------------------
1 | ///
2 | import {IApplicationState, IAction, ActionTypes} from "../infrastructure/index";
3 | import {default as objectAssign} from "object-assign";
4 |
5 | const widthError:string = "Width should be numeric";
6 | const heightError:string = "Height should be numeric";
7 |
8 | const reducerMap:Map = new Map();
9 |
10 | function changeWidth(initialState:IApplicationState, width:any):IApplicationState {
11 | if(isValidNumeric(width)){
12 | return updatedErrorState(initialState, widthError, "width");
13 | }
14 |
15 | const errors = removeError(initialState.errors, widthError);
16 | return objectAssign({}, initialState, {width,errors});
17 | }
18 |
19 | function changeHeight(initialState:IApplicationState, height:any):IApplicationState {
20 | if(isValidNumeric(height)){
21 | return updatedErrorState(initialState, heightError, "height");
22 | }
23 |
24 | const errors = removeError(initialState.errors, heightError);
25 | return objectAssign({}, initialState, {height, errors});
26 | }
27 |
28 | function isValidNumeric(input:any):boolean{
29 | return (!input || isNaN(input));
30 | }
31 |
32 | function updatedErrorState(initialState:IApplicationState, error:string, resetValue:string):IApplicationState{
33 | const errors = (initialState.errors ? addError(initialState.errors, error) : [error]);
34 | return objectAssign({}, initialState, {errors, [resetValue]:0});
35 | }
36 |
37 | function addError(errors:Array, newError:string):Array{
38 | if(errors.indexOf(newError) !== -1) return errors;
39 | return [].concat(errors, [newError]);
40 | }
41 |
42 | function removeError(errors:Array, errorToRemove:string):Array{
43 | if(!errors) return [];
44 |
45 | const index:number = errors.indexOf(errorToRemove);
46 | if(index === -1) return errors;
47 |
48 | return [].concat(errors.slice(0, index), errors.slice(index+1));
49 | }
50 |
51 |
52 | function changeColor(initialState:IApplicationState, color:string){
53 | return objectAssign({}, initialState, {"color":color});
54 | }
55 |
56 | reducerMap.set(ActionTypes.CHANGE_WIDTH, changeWidth);
57 | reducerMap.set(ActionTypes.CHANGE_HEIGHT, changeHeight);
58 | reducerMap.set(ActionTypes.CHANGE_COLOR, changeColor);
59 |
60 | export default function rootReducer(initialState:IApplicationState = {}, action:IAction):IApplicationState{
61 | return reducerMap.has(action.type) ? reducerMap.get(action.type)(initialState, action.payload) : initialState;
62 | }
--------------------------------------------------------------------------------
/tests/reducers/index.spec.ts:
--------------------------------------------------------------------------------
1 | ///
2 | import {IAction, ActionTypes} from "../../src/infrastructure/index";
3 | import {default as actions} from "../../src/actions/index";
4 | import {assert} from "chai";
5 | import rootReducer from "../../src/reducers/index";
6 |
7 | describe("reducers", () => {
8 | describe("unknown action", () => {
9 | it("should return the initialState", () => {
10 | const initialState = {};
11 | Object.freeze(initialState);
12 |
13 | const state = rootReducer(initialState, {type:147,payload:null});
14 | assert.deepEqual(initialState, state);
15 | });
16 | })
17 |
18 | describe("changeWidth", () => {
19 | it("should add an error when the width is not numeric", () => {
20 | const initialState = {};
21 | Object.freeze(initialState);
22 |
23 | const state = rootReducer(initialState, actions.changeWidth("invalid"));
24 | assert.equal(state.errors.length,1);
25 | });
26 |
27 | it("should add the with if it's valid", () => {
28 | const initialState = {};
29 | Object.freeze(initialState);
30 |
31 | const state = rootReducer(initialState, actions.changeWidth(150));
32 | assert.equal(state.width, 150);
33 | });
34 |
35 | it("should remove an error when valid", () => {
36 | const initialState = {errors:["Width should be numeric","other error"]};
37 | Object.freeze(initialState);
38 |
39 | const state = rootReducer(initialState, actions.changeWidth(150));
40 | assert.equal(state.errors.length, 1);
41 | });
42 | });
43 |
44 | describe("changeHeight", () => {
45 | it("should add an error when the height is not numeric", () => {
46 | const initialState = {};
47 | Object.freeze(initialState);
48 |
49 | const state = rootReducer(initialState, actions.changeHeight(null));
50 | assert.equal(state.errors.length,1);
51 | });
52 |
53 | it("should not add the same error twice", () => {
54 | const initialState = {};
55 | Object.freeze(initialState);
56 |
57 | const secondState = rootReducer(initialState, actions.changeHeight(null));
58 | Object.freeze(secondState);
59 |
60 | const state = rootReducer(secondState, actions.changeHeight(null));
61 | assert.equal(state.errors.length,1);
62 | });
63 |
64 | it("should remove an error when new height is valid", () => {
65 | const initialState = {};
66 | Object.freeze(initialState);
67 |
68 | const secondState = rootReducer(initialState, actions.changeHeight(null));
69 | Object.freeze(secondState);
70 |
71 | const state = rootReducer(secondState, actions.changeHeight(7));
72 | assert.equal(state.errors.length,0);
73 | })
74 | });
75 |
76 | describe("changeColor", () => {
77 | it("should change the color", () => {
78 | const initialState = {};
79 | Object.freeze(initialState);
80 |
81 | const state = rootReducer(initialState, actions.changeColor("red"));
82 | assert.equal(state.color, "red");
83 | })
84 | })
85 | })
--------------------------------------------------------------------------------
/typings/mocha/mocha.d.ts:
--------------------------------------------------------------------------------
1 | // Type definitions for mocha 2.2.5
2 | // Project: http://mochajs.org/
3 | // Definitions by: Kazi Manzur Rashid , otiai10 , jt000 , Vadim Macagon
4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped
5 |
6 | interface MochaSetupOptions {
7 | //milliseconds to wait before considering a test slow
8 | slow?: number;
9 |
10 | // timeout in milliseconds
11 | timeout?: number;
12 |
13 | // ui name "bdd", "tdd", "exports" etc
14 | ui?: string;
15 |
16 | //array of accepted globals
17 | globals?: any[];
18 |
19 | // reporter instance (function or string), defaults to `mocha.reporters.Spec`
20 | reporter?: any;
21 |
22 | // bail on the first test failure
23 | bail?: boolean;
24 |
25 | // ignore global leaks
26 | ignoreLeaks?: boolean;
27 |
28 | // grep string or regexp to filter tests with
29 | grep?: any;
30 | }
31 |
32 | interface MochaDone {
33 | (error?: Error): void;
34 | }
35 |
36 | declare var mocha: Mocha;
37 | declare var describe: Mocha.IContextDefinition;
38 | declare var xdescribe: Mocha.IContextDefinition;
39 | // alias for `describe`
40 | declare var context: Mocha.IContextDefinition;
41 | // alias for `describe`
42 | declare var suite: Mocha.IContextDefinition;
43 | declare var it: Mocha.ITestDefinition;
44 | declare var xit: Mocha.ITestDefinition;
45 | // alias for `it`
46 | declare var test: Mocha.ITestDefinition;
47 |
48 | declare function before(action: () => void): void;
49 |
50 | declare function before(action: (done: MochaDone) => void): void;
51 |
52 | declare function before(description: string, action: () => void): void;
53 |
54 | declare function before(description: string, action: (done: MochaDone) => void): void;
55 |
56 | declare function setup(action: () => void): void;
57 |
58 | declare function setup(action: (done: MochaDone) => void): void;
59 |
60 | declare function after(action: () => void): void;
61 |
62 | declare function after(action: (done: MochaDone) => void): void;
63 |
64 | declare function after(description: string, action: () => void): void;
65 |
66 | declare function after(description: string, action: (done: MochaDone) => void): void;
67 |
68 | declare function teardown(action: () => void): void;
69 |
70 | declare function teardown(action: (done: MochaDone) => void): void;
71 |
72 | declare function beforeEach(action: () => void): void;
73 |
74 | declare function beforeEach(action: (done: MochaDone) => void): void;
75 |
76 | declare function beforeEach(description: string, action: () => void): void;
77 |
78 | declare function beforeEach(description: string, action: (done: MochaDone) => void): void;
79 |
80 | declare function suiteSetup(action: () => void): void;
81 |
82 | declare function suiteSetup(action: (done: MochaDone) => void): void;
83 |
84 | declare function afterEach(action: () => void): void;
85 |
86 | declare function afterEach(action: (done: MochaDone) => void): void;
87 |
88 | declare function afterEach(description: string, action: () => void): void;
89 |
90 | declare function afterEach(description: string, action: (done: MochaDone) => void): void;
91 |
92 | declare function suiteTeardown(action: () => void): void;
93 |
94 | declare function suiteTeardown(action: (done: MochaDone) => void): void;
95 |
96 | declare class Mocha {
97 | constructor(options?: {
98 | grep?: RegExp;
99 | ui?: string;
100 | reporter?: string;
101 | timeout?: number;
102 | bail?: boolean;
103 | });
104 |
105 | /** Setup mocha with the given options. */
106 | setup(options: MochaSetupOptions): Mocha;
107 | bail(value?: boolean): Mocha;
108 | addFile(file: string): Mocha;
109 | /** Sets reporter by name, defaults to "spec". */
110 | reporter(name: string): Mocha;
111 | /** Sets reporter constructor, defaults to mocha.reporters.Spec. */
112 | reporter(reporter: (runner: Mocha.IRunner, options: any) => any): Mocha;
113 | ui(value: string): Mocha;
114 | grep(value: string): Mocha;
115 | grep(value: RegExp): Mocha;
116 | invert(): Mocha;
117 | ignoreLeaks(value: boolean): Mocha;
118 | checkLeaks(): Mocha;
119 | /**
120 | * Function to allow assertion libraries to throw errors directly into mocha.
121 | * This is useful when running tests in a browser because window.onerror will
122 | * only receive the 'message' attribute of the Error.
123 | */
124 | throwError(error: Error): void;
125 | /** Enables growl support. */
126 | growl(): Mocha;
127 | globals(value: string): Mocha;
128 | globals(values: string[]): Mocha;
129 | useColors(value: boolean): Mocha;
130 | useInlineDiffs(value: boolean): Mocha;
131 | timeout(value: number): Mocha;
132 | slow(value: number): Mocha;
133 | enableTimeouts(value: boolean): Mocha;
134 | asyncOnly(value: boolean): Mocha;
135 | noHighlighting(value: boolean): Mocha;
136 | /** Runs tests and invokes `onComplete()` when finished. */
137 | run(onComplete?: (failures: number) => void): Mocha.IRunner;
138 | }
139 |
140 | // merge the Mocha class declaration with a module
141 | declare module Mocha {
142 | /** Partial interface for Mocha's `Runnable` class. */
143 | interface IRunnable {
144 | title: string;
145 | fn: Function;
146 | async: boolean;
147 | sync: boolean;
148 | timedOut: boolean;
149 | }
150 |
151 | /** Partial interface for Mocha's `Suite` class. */
152 | interface ISuite {
153 | parent: ISuite;
154 | title: string;
155 |
156 | fullTitle(): string;
157 | }
158 |
159 | /** Partial interface for Mocha's `Test` class. */
160 | interface ITest extends IRunnable {
161 | parent: ISuite;
162 | pending: boolean;
163 |
164 | fullTitle(): string;
165 | }
166 |
167 | /** Partial interface for Mocha's `Runner` class. */
168 | interface IRunner {}
169 |
170 | interface IContextDefinition {
171 | (description: string, spec: () => void): ISuite;
172 | only(description: string, spec: () => void): ISuite;
173 | skip(description: string, spec: () => void): void;
174 | timeout(ms: number): void;
175 | }
176 |
177 | interface ITestDefinition {
178 | (expectation: string, assertion?: () => void): ITest;
179 | (expectation: string, assertion?: (done: MochaDone) => void): ITest;
180 | only(expectation: string, assertion?: () => void): ITest;
181 | only(expectation: string, assertion?: (done: MochaDone) => void): ITest;
182 | skip(expectation: string, assertion?: () => void): void;
183 | skip(expectation: string, assertion?: (done: MochaDone) => void): void;
184 | timeout(ms: number): void;
185 | }
186 |
187 | export module reporters {
188 | export class Base {
189 | stats: {
190 | suites: number;
191 | tests: number;
192 | passes: number;
193 | pending: number;
194 | failures: number;
195 | };
196 |
197 | constructor(runner: IRunner);
198 | }
199 |
200 | export class Doc extends Base {}
201 | export class Dot extends Base {}
202 | export class HTML extends Base {}
203 | export class HTMLCov extends Base {}
204 | export class JSON extends Base {}
205 | export class JSONCov extends Base {}
206 | export class JSONStream extends Base {}
207 | export class Landing extends Base {}
208 | export class List extends Base {}
209 | export class Markdown extends Base {}
210 | export class Min extends Base {}
211 | export class Nyan extends Base {}
212 | export class Progress extends Base {
213 | /**
214 | * @param options.open String used to indicate the start of the progress bar.
215 | * @param options.complete String used to indicate a complete test on the progress bar.
216 | * @param options.incomplete String used to indicate an incomplete test on the progress bar.
217 | * @param options.close String used to indicate the end of the progress bar.
218 | */
219 | constructor(runner: IRunner, options?: {
220 | open?: string;
221 | complete?: string;
222 | incomplete?: string;
223 | close?: string;
224 | });
225 | }
226 | export class Spec extends Base {}
227 | export class TAP extends Base {}
228 | export class XUnit extends Base {
229 | constructor(runner: IRunner, options?: any);
230 | }
231 | }
232 | }
233 |
234 | declare module "mocha" {
235 | export = Mocha;
236 | }
237 |
--------------------------------------------------------------------------------
/dist/app.js:
--------------------------------------------------------------------------------
1 | webpackJsonp([0],[
2 | /* 0 */
3 | /***/ function(module, exports, __webpack_require__) {
4 |
5 | "use strict";
6 |
7 | var _mainViewModel = __webpack_require__(1);
8 |
9 | var _knockout = __webpack_require__(2);
10 |
11 | var _knockout2 = _interopRequireDefault(_knockout);
12 |
13 | var _colorCanvas = __webpack_require__(20);
14 |
15 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16 |
17 | (function () {
18 | window.onload = function () {
19 | _knockout2.default.components.register(_colorCanvas.componentName, _colorCanvas.component);
20 | var node = document.getElementById("app");
21 | _knockout2.default.applyBindings(_mainViewModel.mainViewModel, node);
22 | };
23 | })();
24 |
25 | /***/ },
26 | /* 1 */
27 | /***/ function(module, exports, __webpack_require__) {
28 |
29 | "use strict";
30 |
31 | var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
32 |
33 | Object.defineProperty(exports, "__esModule", {
34 | value: true
35 | });
36 | exports.mainViewModel = undefined;
37 |
38 | var _knockout = __webpack_require__(2);
39 |
40 | var _knockout2 = _interopRequireDefault(_knockout);
41 |
42 | var _index = __webpack_require__(5);
43 |
44 | var _index2 = _interopRequireDefault(_index);
45 |
46 | var _index3 = __webpack_require__(19);
47 |
48 | var _index4 = _interopRequireDefault(_index3);
49 |
50 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
51 |
52 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
53 |
54 | var MainViewModel = (function () {
55 | function MainViewModel() {
56 | var _this = this;
57 |
58 | _classCallCheck(this, MainViewModel);
59 |
60 | this.applicationState = _knockout2.default.observable(this.getState());
61 | this.unsubscribe = _index2.default.subscribe(function () {
62 | console.info("store changed");
63 | _this.applicationState(_this.getState());
64 | });
65 | this.color = _knockout2.default.pureComputed(function () {
66 | return _this.applicationState().color;
67 | });
68 | this.height = _knockout2.default.pureComputed(function () {
69 | return _this.applicationState().height + "px";
70 | });
71 | this.width = _knockout2.default.pureComputed(function () {
72 | return _this.applicationState().width + "px";
73 | });
74 | this.statePrint = _knockout2.default.pureComputed(function () {
75 | return _knockout2.default.toJSON(_this.applicationState());
76 | });
77 | this.errors = _knockout2.default.pureComputed(function () {
78 | return _this.applicationState().errors;
79 | });
80 | this.hasErrors = _knockout2.default.pureComputed(function () {
81 | return _this.errors() && _this.errors().length > 0;
82 | });
83 | }
84 |
85 | _createClass(MainViewModel, [{
86 | key: "updateWidth",
87 | value: function updateWidth(data, e) {
88 | this.updateDimension(e, _index4.default.changeWidth);
89 | }
90 | }, {
91 | key: "updateHeight",
92 | value: function updateHeight(data, e) {
93 | this.updateDimension(e, _index4.default.changeHeight);
94 | }
95 | }, {
96 | key: "updateDimension",
97 | value: function updateDimension(e, actionCreator) {
98 | var value = this.getValueAsInt(e.target);
99 | if (value) {
100 | this.dispatch(actionCreator(value));
101 | }
102 | }
103 | }, {
104 | key: "getValueAsInt",
105 | value: function getValueAsInt(input) {
106 | return input.value;
107 | }
108 | }, {
109 | key: "updateColor",
110 | value: function updateColor(data, e) {
111 | this.dispatch(_index4.default.changeColor(e.target.value));
112 | }
113 | }, {
114 | key: "getState",
115 | value: function getState() {
116 | return _index2.default.getState() || { color: "", width: "", height: "", erros: [] };
117 | }
118 | }, {
119 | key: "dispatch",
120 | value: function dispatch(action) {
121 | return _index2.default.dispatch(action);
122 | }
123 | }]);
124 |
125 | return MainViewModel;
126 | })();
127 |
128 | var mainViewModel = exports.mainViewModel = new MainViewModel();
129 |
130 | /***/ },
131 | /* 2 */,
132 | /* 3 */,
133 | /* 4 */,
134 | /* 5 */
135 | /***/ function(module, exports, __webpack_require__) {
136 |
137 | "use strict";
138 |
139 | Object.defineProperty(exports, "__esModule", {
140 | value: true
141 | });
142 |
143 | var _redux = __webpack_require__(6);
144 |
145 | var _index = __webpack_require__(16);
146 |
147 | var _index2 = _interopRequireDefault(_index);
148 |
149 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
150 |
151 | var store = (0, _redux.createStore)(_index2.default);
152 | exports.default = store;
153 |
154 | /***/ },
155 | /* 6 */,
156 | /* 7 */,
157 | /* 8 */,
158 | /* 9 */,
159 | /* 10 */,
160 | /* 11 */,
161 | /* 12 */,
162 | /* 13 */,
163 | /* 14 */,
164 | /* 15 */,
165 | /* 16 */
166 | /***/ function(module, exports, __webpack_require__) {
167 |
168 | "use strict";
169 |
170 | Object.defineProperty(exports, "__esModule", {
171 | value: true
172 | });
173 | exports.default = rootReducer;
174 |
175 | var _index = __webpack_require__(17);
176 |
177 | var _objectAssign2 = __webpack_require__(18);
178 |
179 | var _objectAssign3 = _interopRequireDefault(_objectAssign2);
180 |
181 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
182 |
183 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
184 |
185 | var widthError = "Width should be numeric";
186 | var heightError = "Height should be numeric";
187 | var reducerMap = new Map();
188 | function changeWidth(initialState, width) {
189 | if (isValidNumeric(width)) {
190 | return updatedErrorState(initialState, widthError, "width");
191 | }
192 | var errors = removeError(initialState.errors, widthError);
193 | return (0, _objectAssign3.default)({}, initialState, { width: width, errors: errors });
194 | }
195 | function changeHeight(initialState, height) {
196 | if (isValidNumeric(height)) {
197 | return updatedErrorState(initialState, heightError, "height");
198 | }
199 | var errors = removeError(initialState.errors, heightError);
200 | return (0, _objectAssign3.default)({}, initialState, { height: height, errors: errors });
201 | }
202 | function isValidNumeric(input) {
203 | return !input || isNaN(input);
204 | }
205 | function updatedErrorState(initialState, error, resetValue) {
206 | var errors = initialState.errors ? addError(initialState.errors, error) : [error];
207 | return (0, _objectAssign3.default)({}, initialState, _defineProperty({ errors: errors }, resetValue, 0));
208 | }
209 | function addError(errors, newError) {
210 | if (errors.indexOf(newError) !== -1) return errors;
211 | return [].concat(errors, [newError]);
212 | }
213 | function removeError(errors, errorToRemove) {
214 | if (!errors) return [];
215 | var index = errors.indexOf(errorToRemove);
216 | if (index === -1) return errors;
217 | return [].concat(errors.slice(0, index), errors.slice(index + 1));
218 | }
219 | function changeColor(initialState, color) {
220 | return (0, _objectAssign3.default)({}, initialState, { "color": color });
221 | }
222 | reducerMap.set(_index.ActionTypes.CHANGE_WIDTH, changeWidth);
223 | reducerMap.set(_index.ActionTypes.CHANGE_HEIGHT, changeHeight);
224 | reducerMap.set(_index.ActionTypes.CHANGE_COLOR, changeColor);
225 | function rootReducer() {
226 | var initialState = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
227 | var action = arguments[1];
228 |
229 | return reducerMap.has(action.type) ? reducerMap.get(action.type)(initialState, action.payload) : initialState;
230 | }
231 |
232 | /***/ },
233 | /* 17 */
234 | /***/ function(module, exports) {
235 |
236 | "use strict";
237 |
238 | Object.defineProperty(exports, "__esModule", {
239 | value: true
240 | });
241 | var ActionTypes = exports.ActionTypes = undefined;
242 | (function (ActionTypes) {
243 | ActionTypes[ActionTypes["CHANGE_COLOR"] = 0] = "CHANGE_COLOR";
244 | ActionTypes[ActionTypes["CHANGE_WIDTH"] = 1] = "CHANGE_WIDTH";
245 | ActionTypes[ActionTypes["CHANGE_HEIGHT"] = 2] = "CHANGE_HEIGHT";
246 | })(ActionTypes || (exports.ActionTypes = ActionTypes = {}));
247 |
248 | /***/ },
249 | /* 18 */,
250 | /* 19 */
251 | /***/ function(module, exports, __webpack_require__) {
252 |
253 | "use strict";
254 |
255 | Object.defineProperty(exports, "__esModule", {
256 | value: true
257 | });
258 |
259 | var _index = __webpack_require__(17);
260 |
261 | function changeWidth(width) {
262 | return {
263 | type: _index.ActionTypes.CHANGE_WIDTH,
264 | payload: width
265 | };
266 | }
267 | function changeHeight(height) {
268 | return {
269 | type: _index.ActionTypes.CHANGE_HEIGHT,
270 | payload: height
271 | };
272 | }
273 | function changeColor(color) {
274 | return {
275 | type: _index.ActionTypes.CHANGE_COLOR,
276 | payload: color
277 | };
278 | }
279 | exports.default = {
280 | changeWidth: changeWidth,
281 | changeHeight: changeHeight,
282 | changeColor: changeColor
283 | };
284 |
285 | /***/ },
286 | /* 20 */
287 | /***/ function(module, exports, __webpack_require__) {
288 |
289 | "use strict";
290 |
291 | Object.defineProperty(exports, "__esModule", {
292 | value: true
293 | });
294 | exports.component = exports.componentName = undefined;
295 |
296 | var _knockout = __webpack_require__(2);
297 |
298 | var _knockout2 = _interopRequireDefault(_knockout);
299 |
300 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
301 |
302 | var componentName = exports.componentName = "color-canvas";
303 | var component = exports.component = {
304 | viewModel: function viewModel(params) {
305 | this.style = _knockout2.default.pureComputed(function () {
306 | return {
307 | "display": "block",
308 | "backgroundColor": params.color(),
309 | "width": params.width(),
310 | "height": params.height()
311 | };
312 | });
313 | },
314 | template: "\n\t\t\n\t"
315 | };
316 |
317 | /***/ }
318 | ]);
--------------------------------------------------------------------------------
/typings/chai/chai.d.ts:
--------------------------------------------------------------------------------
1 | // Type definitions for chai 3.2.0
2 | // Project: http://chaijs.com/
3 | // Definitions by: Jed Mao ,
4 | // Bart van der Schoor ,
5 | // Andrew Brown ,
6 | // Olivier Chevet
7 | // Definitions: https://github.com/borisyankov/DefinitelyTyped
8 |
9 | //
10 |
11 | declare module Chai {
12 |
13 | interface ChaiStatic {
14 | expect: ExpectStatic;
15 | should(): Should;
16 | /**
17 | * Provides a way to extend the internals of Chai
18 | */
19 | use(fn: (chai: any, utils: any) => void): any;
20 | assert: AssertStatic;
21 | config: Config;
22 | AssertionError: AssertionError;
23 | }
24 |
25 | export interface ExpectStatic extends AssertionStatic {
26 | fail(actual?: any, expected?: any, message?: string, operator?: string): void;
27 | }
28 |
29 | export interface AssertStatic extends Assert {
30 | }
31 |
32 | export interface AssertionStatic {
33 | (target: any, message?: string): Assertion;
34 | }
35 |
36 | interface ShouldAssertion {
37 | equal(value1: any, value2: any, message?: string): void;
38 | Throw: ShouldThrow;
39 | throw: ShouldThrow;
40 | exist(value: any, message?: string): void;
41 | }
42 |
43 | interface Should extends ShouldAssertion {
44 | not: ShouldAssertion;
45 | fail(actual: any, expected: any, message?: string, operator?: string): void;
46 | }
47 |
48 | interface ShouldThrow {
49 | (actual: Function): void;
50 | (actual: Function, expected: string|RegExp, message?: string): void;
51 | (actual: Function, constructor: Error|Function, expected?: string|RegExp, message?: string): void;
52 | }
53 |
54 | interface Assertion extends LanguageChains, NumericComparison, TypeComparison {
55 | not: Assertion;
56 | deep: Deep;
57 | any: KeyFilter;
58 | all: KeyFilter;
59 | a: TypeComparison;
60 | an: TypeComparison;
61 | include: Include;
62 | includes: Include;
63 | contain: Include;
64 | contains: Include;
65 | ok: Assertion;
66 | true: Assertion;
67 | false: Assertion;
68 | null: Assertion;
69 | undefined: Assertion;
70 | NaN: Assertion;
71 | exist: Assertion;
72 | empty: Assertion;
73 | arguments: Assertion;
74 | Arguments: Assertion;
75 | equal: Equal;
76 | equals: Equal;
77 | eq: Equal;
78 | eql: Equal;
79 | eqls: Equal;
80 | property: Property;
81 | ownProperty: OwnProperty;
82 | haveOwnProperty: OwnProperty;
83 | ownPropertyDescriptor: OwnPropertyDescriptor;
84 | haveOwnPropertyDescriptor: OwnPropertyDescriptor;
85 | length: Length;
86 | lengthOf: Length;
87 | match: Match;
88 | matches: Match;
89 | string(string: string, message?: string): Assertion;
90 | keys: Keys;
91 | key(string: string): Assertion;
92 | throw: Throw;
93 | throws: Throw;
94 | Throw: Throw;
95 | respondTo: RespondTo;
96 | respondsTo: RespondTo;
97 | itself: Assertion;
98 | satisfy: Satisfy;
99 | satisfies: Satisfy;
100 | closeTo(expected: number, delta: number, message?: string): Assertion;
101 | members: Members;
102 | increase: PropertyChange;
103 | increases: PropertyChange;
104 | decrease: PropertyChange;
105 | decreases: PropertyChange;
106 | change: PropertyChange;
107 | changes: PropertyChange;
108 | extensible: Assertion;
109 | sealed: Assertion;
110 | frozen: Assertion;
111 |
112 | }
113 |
114 | interface LanguageChains {
115 | to: Assertion;
116 | be: Assertion;
117 | been: Assertion;
118 | is: Assertion;
119 | that: Assertion;
120 | which: Assertion;
121 | and: Assertion;
122 | has: Assertion;
123 | have: Assertion;
124 | with: Assertion;
125 | at: Assertion;
126 | of: Assertion;
127 | same: Assertion;
128 | }
129 |
130 | interface NumericComparison {
131 | above: NumberComparer;
132 | gt: NumberComparer;
133 | greaterThan: NumberComparer;
134 | least: NumberComparer;
135 | gte: NumberComparer;
136 | below: NumberComparer;
137 | lt: NumberComparer;
138 | lessThan: NumberComparer;
139 | most: NumberComparer;
140 | lte: NumberComparer;
141 | within(start: number, finish: number, message?: string): Assertion;
142 | }
143 |
144 | interface NumberComparer {
145 | (value: number, message?: string): Assertion;
146 | }
147 |
148 | interface TypeComparison {
149 | (type: string, message?: string): Assertion;
150 | instanceof: InstanceOf;
151 | instanceOf: InstanceOf;
152 | }
153 |
154 | interface InstanceOf {
155 | (constructor: Object, message?: string): Assertion;
156 | }
157 |
158 | interface Deep {
159 | equal: Equal;
160 | include: Include;
161 | property: Property;
162 | members: Members;
163 | }
164 |
165 | interface KeyFilter {
166 | keys: Keys;
167 | }
168 |
169 | interface Equal {
170 | (value: any, message?: string): Assertion;
171 | }
172 |
173 | interface Property {
174 | (name: string, value?: any, message?: string): Assertion;
175 | }
176 |
177 | interface OwnProperty {
178 | (name: string, message?: string): Assertion;
179 | }
180 |
181 | interface OwnPropertyDescriptor {
182 | (name: string, descriptor: PropertyDescriptor, message?: string): Assertion;
183 | (name: string, message?: string): Assertion;
184 | }
185 |
186 | interface Length extends LanguageChains, NumericComparison {
187 | (length: number, message?: string): Assertion;
188 | }
189 |
190 | interface Include {
191 | (value: Object, message?: string): Assertion;
192 | (value: string, message?: string): Assertion;
193 | (value: number, message?: string): Assertion;
194 | keys: Keys;
195 | members: Members;
196 | any: KeyFilter;
197 | all: KeyFilter;
198 | }
199 |
200 | interface Match {
201 | (regexp: RegExp|string, message?: string): Assertion;
202 | }
203 |
204 | interface Keys {
205 | (...keys: string[]): Assertion;
206 | (keys: any[]): Assertion;
207 | (keys: Object): Assertion;
208 | }
209 |
210 | interface Throw {
211 | (): Assertion;
212 | (expected: string, message?: string): Assertion;
213 | (expected: RegExp, message?: string): Assertion;
214 | (constructor: Error, expected?: string, message?: string): Assertion;
215 | (constructor: Error, expected?: RegExp, message?: string): Assertion;
216 | (constructor: Function, expected?: string, message?: string): Assertion;
217 | (constructor: Function, expected?: RegExp, message?: string): Assertion;
218 | }
219 |
220 | interface RespondTo {
221 | (method: string, message?: string): Assertion;
222 | }
223 |
224 | interface Satisfy {
225 | (matcher: Function, message?: string): Assertion;
226 | }
227 |
228 | interface Members {
229 | (set: any[], message?: string): Assertion;
230 | }
231 |
232 | interface PropertyChange {
233 | (object: Object, prop: string, msg?: string): Assertion;
234 | }
235 |
236 | export interface Assert {
237 | /**
238 | * @param expression Expression to test for truthiness.
239 | * @param message Message to display on error.
240 | */
241 | (expression: any, message?: string): void;
242 |
243 | fail(actual?: any, expected?: any, msg?: string, operator?: string): void;
244 |
245 | ok(val: any, msg?: string): void;
246 | isOk(val: any, msg?: string): void;
247 | notOk(val: any, msg?: string): void;
248 | isNotOk(val: any, msg?: string): void;
249 |
250 | equal(act: any, exp: any, msg?: string): void;
251 | notEqual(act: any, exp: any, msg?: string): void;
252 |
253 | strictEqual(act: any, exp: any, msg?: string): void;
254 | notStrictEqual(act: any, exp: any, msg?: string): void;
255 |
256 | deepEqual(act: any, exp: any, msg?: string): void;
257 | notDeepEqual(act: any, exp: any, msg?: string): void;
258 |
259 | isTrue(val: any, msg?: string): void;
260 | isFalse(val: any, msg?: string): void;
261 |
262 | isNull(val: any, msg?: string): void;
263 | isNotNull(val: any, msg?: string): void;
264 |
265 | isUndefined(val: any, msg?: string): void;
266 | isDefined(val: any, msg?: string): void;
267 |
268 | isNaN(val: any, msg?: string): void;
269 | isNotNaN(val: any, msg?: string): void;
270 |
271 | isAbove(val: number, abv: number, msg?: string): void;
272 | isBelow(val: number, blw: number, msg?: string): void;
273 |
274 | isFunction(val: any, msg?: string): void;
275 | isNotFunction(val: any, msg?: string): void;
276 |
277 | isObject(val: any, msg?: string): void;
278 | isNotObject(val: any, msg?: string): void;
279 |
280 | isArray(val: any, msg?: string): void;
281 | isNotArray(val: any, msg?: string): void;
282 |
283 | isString(val: any, msg?: string): void;
284 | isNotString(val: any, msg?: string): void;
285 |
286 | isNumber(val: any, msg?: string): void;
287 | isNotNumber(val: any, msg?: string): void;
288 |
289 | isBoolean(val: any, msg?: string): void;
290 | isNotBoolean(val: any, msg?: string): void;
291 |
292 | typeOf(val: any, type: string, msg?: string): void;
293 | notTypeOf(val: any, type: string, msg?: string): void;
294 |
295 | instanceOf(val: any, type: Function, msg?: string): void;
296 | notInstanceOf(val: any, type: Function, msg?: string): void;
297 |
298 | include(exp: string, inc: any, msg?: string): void;
299 | include(exp: any[], inc: any, msg?: string): void;
300 |
301 | notInclude(exp: string, inc: any, msg?: string): void;
302 | notInclude(exp: any[], inc: any, msg?: string): void;
303 |
304 | match(exp: any, re: RegExp, msg?: string): void;
305 | notMatch(exp: any, re: RegExp, msg?: string): void;
306 |
307 | property(obj: Object, prop: string, msg?: string): void;
308 | notProperty(obj: Object, prop: string, msg?: string): void;
309 | deepProperty(obj: Object, prop: string, msg?: string): void;
310 | notDeepProperty(obj: Object, prop: string, msg?: string): void;
311 |
312 | propertyVal(obj: Object, prop: string, val: any, msg?: string): void;
313 | propertyNotVal(obj: Object, prop: string, val: any, msg?: string): void;
314 |
315 | deepPropertyVal(obj: Object, prop: string, val: any, msg?: string): void;
316 | deepPropertyNotVal(obj: Object, prop: string, val: any, msg?: string): void;
317 |
318 | lengthOf(exp: any, len: number, msg?: string): void;
319 | //alias frenzy
320 | throw(fn: Function, msg?: string): void;
321 | throw(fn: Function, regExp: RegExp): void;
322 | throw(fn: Function, errType: Function, msg?: string): void;
323 | throw(fn: Function, errType: Function, regExp: RegExp): void;
324 |
325 | throws(fn: Function, msg?: string): void;
326 | throws(fn: Function, regExp: RegExp): void;
327 | throws(fn: Function, errType: Function, msg?: string): void;
328 | throws(fn: Function, errType: Function, regExp: RegExp): void;
329 |
330 | Throw(fn: Function, msg?: string): void;
331 | Throw(fn: Function, regExp: RegExp): void;
332 | Throw(fn: Function, errType: Function, msg?: string): void;
333 | Throw(fn: Function, errType: Function, regExp: RegExp): void;
334 |
335 | doesNotThrow(fn: Function, msg?: string): void;
336 | doesNotThrow(fn: Function, regExp: RegExp): void;
337 | doesNotThrow(fn: Function, errType: Function, msg?: string): void;
338 | doesNotThrow(fn: Function, errType: Function, regExp: RegExp): void;
339 |
340 | operator(val: any, operator: string, val2: any, msg?: string): void;
341 | closeTo(act: number, exp: number, delta: number, msg?: string): void;
342 |
343 | sameMembers(set1: any[], set2: any[], msg?: string): void;
344 | sameDeepMembers(set1: any[], set2: any[], msg?: string): void;
345 | includeMembers(superset: any[], subset: any[], msg?: string): void;
346 |
347 | ifError(val: any, msg?: string): void;
348 |
349 | isExtensible(obj: {}, msg?: string): void;
350 | extensible(obj: {}, msg?: string): void;
351 | isNotExtensible(obj: {}, msg?: string): void;
352 | notExtensible(obj: {}, msg?: string): void;
353 |
354 | isSealed(obj: {}, msg?: string): void;
355 | sealed(obj: {}, msg?: string): void;
356 | isNotSealed(obj: {}, msg?: string): void;
357 | notSealed(obj: {}, msg?: string): void;
358 |
359 | isFrozen(obj: Object, msg?: string): void;
360 | frozen(obj: Object, msg?: string): void;
361 | isNotFrozen(obj: Object, msg?: string): void;
362 | notFrozen(obj: Object, msg?: string): void;
363 |
364 |
365 | }
366 |
367 | export interface Config {
368 | includeStack: boolean;
369 | }
370 |
371 | export class AssertionError {
372 | constructor(message: string, _props?: any, ssf?: Function);
373 | name: string;
374 | message: string;
375 | showDiff: boolean;
376 | stack: string;
377 | }
378 | }
379 |
380 | declare var chai: Chai.ChaiStatic;
381 |
382 | declare module "chai" {
383 | export = chai;
384 | }
385 |
386 | interface Object {
387 | should: Chai.Assertion;
388 | }
389 |
--------------------------------------------------------------------------------
/typings/knockout/knockout.d.ts:
--------------------------------------------------------------------------------
1 | // Type definitions for Knockout v3.2.0
2 | // Project: http://knockoutjs.com
3 | // Definitions by: Boris Yankov , Igor Oleinikov , Clément Bourgeois
4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped
5 |
6 |
7 | interface KnockoutSubscribableFunctions {
8 | [key: string]: KnockoutBindingHandler;
9 |
10 | notifySubscribers(valueToWrite?: T, event?: string): void;
11 | }
12 |
13 | interface KnockoutComputedFunctions {
14 | [key: string]: KnockoutBindingHandler;
15 | }
16 |
17 | interface KnockoutObservableFunctions {
18 | [key: string]: KnockoutBindingHandler;
19 |
20 | equalityComparer(a: any, b: any): boolean;
21 | }
22 |
23 | interface KnockoutObservableArrayFunctions {
24 | // General Array functions
25 | indexOf(searchElement: T, fromIndex?: number): number;
26 | slice(start: number, end?: number): T[];
27 | splice(start: number): T[];
28 | splice(start: number, deleteCount: number, ...items: T[]): T[];
29 | pop(): T;
30 | push(...items: T[]): void;
31 | shift(): T;
32 | unshift(...items: T[]): number;
33 | reverse(): T[];
34 | sort(): void;
35 | sort(compareFunction: (left: T, right: T) => number): void;
36 |
37 | // Ko specific
38 | [key: string]: KnockoutBindingHandler;
39 |
40 | replace(oldItem: T, newItem: T): void;
41 |
42 | remove(item: T): T[];
43 | remove(removeFunction: (item: T) => boolean): T[];
44 | removeAll(items: T[]): T[];
45 | removeAll(): T[];
46 |
47 | destroy(item: T): void;
48 | destroy(destroyFunction: (item: T) => boolean): void;
49 | destroyAll(items: T[]): void;
50 | destroyAll(): void;
51 | }
52 |
53 | interface KnockoutSubscribableStatic {
54 | fn: KnockoutSubscribableFunctions;
55 |
56 | new (): KnockoutSubscribable;
57 | }
58 |
59 | interface KnockoutSubscription {
60 | dispose(): void;
61 | }
62 |
63 | interface KnockoutSubscribable extends KnockoutSubscribableFunctions {
64 | subscribe(callback: (newValue: T) => void, target?: any, event?: string): KnockoutSubscription;
65 | subscribe(callback: (newValue: TEvent) => void, target: any, event: string): KnockoutSubscription;
66 | extend(requestedExtenders: { [key: string]: any; }): KnockoutSubscribable;
67 | getSubscriptionsCount(): number;
68 | }
69 |
70 | interface KnockoutComputedStatic {
71 | fn: KnockoutComputedFunctions;
72 |
73 | (): KnockoutComputed;
74 | (func: () => T, context?: any, options?: any): KnockoutComputed;
75 | (def: KnockoutComputedDefine, context?: any): KnockoutComputed;
76 | }
77 |
78 | interface KnockoutComputed extends KnockoutObservable, KnockoutComputedFunctions {
79 | fn: KnockoutComputedFunctions;
80 |
81 | dispose(): void;
82 | isActive(): boolean;
83 | getDependenciesCount(): number;
84 | extend(requestedExtenders: { [key: string]: any; }): KnockoutComputed;
85 | }
86 |
87 | interface KnockoutObservableArrayStatic {
88 | fn: KnockoutObservableArrayFunctions;
89 |
90 | (value?: T[]): KnockoutObservableArray;
91 | }
92 |
93 | interface KnockoutObservableArray extends KnockoutObservable, KnockoutObservableArrayFunctions {
94 | extend(requestedExtenders: { [key: string]: any; }): KnockoutObservableArray;
95 | }
96 |
97 | interface KnockoutObservableStatic {
98 | fn: KnockoutObservableFunctions;
99 |
100 | (value?: T): KnockoutObservable;
101 | }
102 |
103 | interface KnockoutObservable extends KnockoutSubscribable, KnockoutObservableFunctions {
104 | (): T;
105 | (value: T): void;
106 |
107 | peek(): T;
108 | valueHasMutated?:{(): void;};
109 | valueWillMutate?:{(): void;};
110 | extend(requestedExtenders: { [key: string]: any; }): KnockoutObservable;
111 | }
112 |
113 | interface KnockoutComputedDefine {
114 | read(): T;
115 | write? (value: T): void;
116 | disposeWhenNodeIsRemoved?: Node;
117 | disposeWhen? (): boolean;
118 | owner?: any;
119 | deferEvaluation?: boolean;
120 | pure?: boolean;
121 | }
122 |
123 | interface KnockoutBindingContext {
124 | $parent: any;
125 | $parents: any[];
126 | $root: any;
127 | $data: any;
128 | $rawData: any | KnockoutObservable;
129 | $index?: KnockoutObservable;
130 | $parentContext?: KnockoutBindingContext;
131 | $component: any;
132 | $componentTemplateNodes: Node[];
133 |
134 | extend(properties: any): any;
135 | createChildContext(dataItemOrAccessor: any, dataItemAlias?: any, extendCallback?: Function): any;
136 | }
137 |
138 | interface KnockoutAllBindingsAccessor {
139 | (): any;
140 | get(name: string): any;
141 | has(name: string): boolean;
142 | }
143 |
144 | interface KnockoutBindingHandler {
145 | after?: Array;
146 | init?: (element: any, valueAccessor: () => any, allBindingsAccessor?: KnockoutAllBindingsAccessor, viewModel?: any, bindingContext?: KnockoutBindingContext) => void | { controlsDescendantBindings: boolean; };
147 | update?: (element: any, valueAccessor: () => any, allBindingsAccessor?: KnockoutAllBindingsAccessor, viewModel?: any, bindingContext?: KnockoutBindingContext) => void;
148 | options?: any;
149 | preprocess?: (value: string, name: string, addBindingCallback?: (name: string, value: string) => void) => string;
150 | }
151 |
152 | interface KnockoutBindingHandlers {
153 | [bindingHandler: string]: KnockoutBindingHandler;
154 |
155 | // Controlling text and appearance
156 | visible: KnockoutBindingHandler;
157 | text: KnockoutBindingHandler;
158 | html: KnockoutBindingHandler;
159 | css: KnockoutBindingHandler;
160 | style: KnockoutBindingHandler;
161 | attr: KnockoutBindingHandler;
162 |
163 | // Control Flow
164 | foreach: KnockoutBindingHandler;
165 | if: KnockoutBindingHandler;
166 | ifnot: KnockoutBindingHandler;
167 | with: KnockoutBindingHandler;
168 |
169 | // Working with form fields
170 | click: KnockoutBindingHandler;
171 | event: KnockoutBindingHandler;
172 | submit: KnockoutBindingHandler;
173 | enable: KnockoutBindingHandler;
174 | disable: KnockoutBindingHandler;
175 | value: KnockoutBindingHandler;
176 | textInput: KnockoutBindingHandler;
177 | hasfocus: KnockoutBindingHandler;
178 | checked: KnockoutBindingHandler;
179 | options: KnockoutBindingHandler;
180 | selectedOptions: KnockoutBindingHandler;
181 | uniqueName: KnockoutBindingHandler;
182 |
183 | // Rendering templates
184 | template: KnockoutBindingHandler;
185 |
186 | // Components (new for v3.2)
187 | component: KnockoutBindingHandler;
188 | }
189 |
190 | interface KnockoutMemoization {
191 | memoize(callback: () => string): string;
192 | unmemoize(memoId: string, callbackParams: any[]): boolean;
193 | unmemoizeDomNodeAndDescendants(domNode: any, extraCallbackParamsArray: any[]): boolean;
194 | parseMemoText(memoText: string): string;
195 | }
196 |
197 | interface KnockoutVirtualElement {}
198 |
199 | interface KnockoutVirtualElements {
200 | allowedBindings: { [bindingName: string]: boolean; };
201 | emptyNode(node: KnockoutVirtualElement ): void;
202 | firstChild(node: KnockoutVirtualElement ): KnockoutVirtualElement;
203 | insertAfter( container: KnockoutVirtualElement, nodeToInsert: Node, insertAfter: Node ): void;
204 | nextSibling(node: KnockoutVirtualElement): Node;
205 | prepend(node: KnockoutVirtualElement, toInsert: Node ): void;
206 | setDomNodeChildren(node: KnockoutVirtualElement, newChildren: { length: number;[index: number]: Node; } ): void;
207 | childNodes(node: KnockoutVirtualElement ): Node[];
208 | }
209 |
210 | interface KnockoutExtenders {
211 | throttle(target: any, timeout: number): KnockoutComputed;
212 | notify(target: any, notifyWhen: string): any;
213 |
214 | rateLimit(target: any, timeout: number): any;
215 | rateLimit(target: any, options: { timeout: number; method?: string; }): any;
216 |
217 | trackArrayChanges(target: any): any;
218 | }
219 |
220 | //
221 | // NOTE TO MAINTAINERS AND CONTRIBUTORS : pay attention to only include symbols that are
222 | // publicly exported in the minified version of ko, without that you can give the false
223 | // impression that some functions will be available in production builds.
224 | //
225 | interface KnockoutUtils {
226 | //////////////////////////////////
227 | // utils.domData.js
228 | //////////////////////////////////
229 |
230 | domData: {
231 | get (node: Element, key: string): any;
232 |
233 | set (node: Element, key: string, value: any): void;
234 |
235 | getAll(node: Element, createIfNotFound: boolean): any;
236 |
237 | clear(node: Element): boolean;
238 | };
239 |
240 | //////////////////////////////////
241 | // utils.domNodeDisposal.js
242 | //////////////////////////////////
243 |
244 | domNodeDisposal: {
245 | addDisposeCallback(node: Element, callback: Function): void;
246 |
247 | removeDisposeCallback(node: Element, callback: Function): void;
248 |
249 | cleanNode(node: Node): Element;
250 |
251 | removeNode(node: Node): void;
252 | };
253 |
254 | addOrRemoveItem(array: T[] | KnockoutObservable, value: T, included: T): void;
255 |
256 | arrayFilter(array: T[], predicate: (item: T) => boolean): T[];
257 |
258 | arrayFirst(array: T[], predicate: (item: T) => boolean, predicateOwner?: any): T;
259 |
260 | arrayForEach(array: T[], action: (item: T, index: number) => void): void;
261 |
262 | arrayGetDistinctValues(array: T[]): T[];
263 |
264 | arrayIndexOf(array: T[], item: T): number;
265 |
266 | arrayMap(array: T[], mapping: (item: T) => U): U[];
267 |
268 | arrayPushAll(array: T[] | KnockoutObservableArray, valuesToPush: T[]): T[];
269 |
270 | arrayRemoveItem(array: any[], itemToRemove: any): void;
271 |
272 | compareArrays(a: T[], b: T[]): Array>;
273 |
274 | extend(target: Object, source: Object): Object;
275 |
276 | fieldsIncludedWithJsonPost: any[];
277 |
278 | getFormFields(form: any, fieldName: string): any[];
279 |
280 | objectForEach(obj: any, action: (key: any, value: any) => void): void;
281 |
282 | parseHtmlFragment(html: string): any[];
283 |
284 | parseJson(jsonString: string): any;
285 |
286 | postJson(urlOrForm: any, data: any, options: any): void;
287 |
288 | peekObservable(value: KnockoutObservable): T;
289 |
290 | range(min: any, max: any): any;
291 |
292 | registerEventHandler(element: any, eventType: any, handler: Function): void;
293 |
294 | setHtml(node: Element, html: () => string): void;
295 |
296 | setHtml(node: Element, html: string): void;
297 |
298 | setTextContent(element: any, textContent: string | KnockoutObservable): void;
299 |
300 | stringifyJson(data: any, replacer?: Function, space?: string): string;
301 |
302 | toggleDomNodeCssClass(node: any, className: string, shouldHaveClass: boolean): void;
303 |
304 | triggerEvent(element: any, eventType: any): void;
305 |
306 | unwrapObservable(value: KnockoutObservable | T): T;
307 |
308 | // NOT PART OF THE MINIFIED API SURFACE (ONLY IN knockout-{version}.debug.js) https://github.com/SteveSanderson/knockout/issues/670
309 | // forceRefresh(node: any): void;
310 | // ieVersion: number;
311 | // isIe6: boolean;
312 | // isIe7: boolean;
313 | // jQueryHtmlParse(html: string): any[];
314 | // makeArray(arrayLikeObject: any): any[];
315 | // moveCleanedNodesToContainerElement(nodes: any[]): HTMLElement;
316 | // replaceDomNodes(nodeToReplaceOrNodeArray: any, newNodesArray: any[]): void;
317 | // setDomNodeChildren(domNode: any, childNodes: any[]): void;
318 | // setElementName(element: any, name: string): void;
319 | // setOptionNodeSelectionState(optionNode: any, isSelected: boolean): void;
320 | // simpleHtmlParse(html: string): any[];
321 | // stringStartsWith(str: string, startsWith: string): boolean;
322 | // stringTokenize(str: string, delimiter: string): string[];
323 | // stringTrim(str: string): string;
324 | // tagNameLower(element: any): string;
325 | }
326 |
327 | interface KnockoutArrayChange {
328 | status: string;
329 | value: T;
330 | index: number;
331 | moved?: number;
332 | }
333 |
334 | //////////////////////////////////
335 | // templateSources.js
336 | //////////////////////////////////
337 |
338 | interface KnockoutTemplateSourcesDomElement {
339 | text(): any;
340 | text(value: any): void;
341 |
342 | data(key: string): any;
343 | data(key: string, value: any): any;
344 | }
345 |
346 | interface KnockoutTemplateAnonymous extends KnockoutTemplateSourcesDomElement {
347 | nodes(): any;
348 | nodes(value: any): void;
349 | }
350 |
351 | interface KnockoutTemplateSources {
352 |
353 | domElement: {
354 | prototype: KnockoutTemplateSourcesDomElement
355 | new (element: Element): KnockoutTemplateSourcesDomElement
356 | };
357 |
358 | anonymousTemplate: {
359 | prototype: KnockoutTemplateAnonymous;
360 | new (element: Element): KnockoutTemplateAnonymous;
361 | };
362 | }
363 |
364 | //////////////////////////////////
365 | // nativeTemplateEngine.js
366 | //////////////////////////////////
367 |
368 | interface KnockoutNativeTemplateEngine {
369 |
370 | renderTemplateSource(templateSource: Object, bindingContext?: KnockoutBindingContext, options?: Object): any[];
371 | }
372 |
373 | //////////////////////////////////
374 | // templateEngine.js
375 | //////////////////////////////////
376 |
377 | interface KnockoutTemplateEngine extends KnockoutNativeTemplateEngine {
378 |
379 | createJavaScriptEvaluatorBlock(script: string): string;
380 |
381 | makeTemplateSource(template: any, templateDocument?: Document): any;
382 |
383 | renderTemplate(template: any, bindingContext: KnockoutBindingContext, options: Object, templateDocument: Document): any;
384 |
385 | isTemplateRewritten(template: any, templateDocument: Document): boolean;
386 |
387 | rewriteTemplate(template: any, rewriterCallback: Function, templateDocument: Document): void;
388 | }
389 |
390 | /////////////////////////////////
391 |
392 | interface KnockoutStatic {
393 | utils: KnockoutUtils;
394 | memoization: KnockoutMemoization;
395 |
396 | bindingHandlers: KnockoutBindingHandlers;
397 | getBindingHandler(handler: string): KnockoutBindingHandler;
398 |
399 | virtualElements: KnockoutVirtualElements;
400 | extenders: KnockoutExtenders;
401 |
402 | applyBindings(viewModelOrBindingContext?: any, rootNode?: any): void;
403 | applyBindingsToDescendants(viewModelOrBindingContext: any, rootNode: any): void;
404 | applyBindingAccessorsToNode(node: Node, bindings: (bindingContext: KnockoutBindingContext, node: Node) => {}, bindingContext: KnockoutBindingContext): void;
405 | applyBindingAccessorsToNode(node: Node, bindings: {}, bindingContext: KnockoutBindingContext): void;
406 | applyBindingAccessorsToNode(node: Node, bindings: (bindingContext: KnockoutBindingContext, node: Node) => {}, viewModel: any): void;
407 | applyBindingAccessorsToNode(node: Node, bindings: {}, viewModel: any): void;
408 | applyBindingsToNode(node: Node, bindings: any, viewModelOrBindingContext?: any): any;
409 |
410 | subscribable: KnockoutSubscribableStatic;
411 | observable: KnockoutObservableStatic;
412 |
413 | computed: KnockoutComputedStatic;
414 | pureComputed(evaluatorFunction: () => T, context?: any): KnockoutComputed;
415 | pureComputed(options: KnockoutComputedDefine, context?: any): KnockoutComputed;
416 |
417 | observableArray: KnockoutObservableArrayStatic;
418 |
419 | contextFor(node: any): any;
420 | isSubscribable(instance: any): boolean;
421 | toJSON(viewModel: any, replacer?: Function, space?: any): string;
422 | toJS(viewModel: any): any;
423 | isObservable(instance: any): boolean;
424 | isWriteableObservable(instance: any): boolean;
425 | isComputed(instance: any): boolean;
426 | dataFor(node: any): any;
427 | removeNode(node: Element): void;
428 | cleanNode(node: Element): Element;
429 | renderTemplate(template: Function, viewModel: any, options?: any, target?: any, renderMode?: any): any;
430 | renderTemplate(template: string, viewModel: any, options?: any, target?: any, renderMode?: any): any;
431 | unwrap(value: KnockoutObservable | T): T;
432 |
433 | computedContext: KnockoutComputedContext;
434 |
435 | //////////////////////////////////
436 | // templateSources.js
437 | //////////////////////////////////
438 |
439 | templateSources: KnockoutTemplateSources;
440 |
441 | //////////////////////////////////
442 | // templateEngine.js
443 | //////////////////////////////////
444 |
445 | templateEngine: {
446 |
447 | prototype: KnockoutTemplateEngine;
448 |
449 | new (): KnockoutTemplateEngine;
450 | };
451 |
452 | //////////////////////////////////
453 | // templateRewriting.js
454 | //////////////////////////////////
455 |
456 | templateRewriting: {
457 |
458 | ensureTemplateIsRewritten(template: Node, templateEngine: KnockoutTemplateEngine, templateDocument: Document): any;
459 | ensureTemplateIsRewritten(template: string, templateEngine: KnockoutTemplateEngine, templateDocument: Document): any;
460 |
461 | memoizeBindingAttributeSyntax(htmlString: string, templateEngine: KnockoutTemplateEngine): any;
462 |
463 | applyMemoizedBindingsToNextSibling(bindings: any, nodeName: string): string;
464 | };
465 |
466 | //////////////////////////////////
467 | // nativeTemplateEngine.js
468 | //////////////////////////////////
469 |
470 | nativeTemplateEngine: {
471 |
472 | prototype: KnockoutNativeTemplateEngine;
473 |
474 | new (): KnockoutNativeTemplateEngine;
475 |
476 | instance: KnockoutNativeTemplateEngine;
477 | };
478 |
479 | //////////////////////////////////
480 | // jqueryTmplTemplateEngine.js
481 | //////////////////////////////////
482 |
483 | jqueryTmplTemplateEngine: {
484 |
485 | prototype: KnockoutTemplateEngine;
486 |
487 | renderTemplateSource(templateSource: Object, bindingContext: KnockoutBindingContext, options: Object): Node[];
488 |
489 | createJavaScriptEvaluatorBlock(script: string): string;
490 |
491 | addTemplate(templateName: string, templateMarkup: string): void;
492 | };
493 |
494 | //////////////////////////////////
495 | // templating.js
496 | //////////////////////////////////
497 |
498 | setTemplateEngine(templateEngine: KnockoutNativeTemplateEngine): void;
499 |
500 | renderTemplate(template: Function, dataOrBindingContext: KnockoutBindingContext, options: Object, targetNodeOrNodeArray: Node, renderMode: string): any;
501 | renderTemplate(template: any, dataOrBindingContext: KnockoutBindingContext, options: Object, targetNodeOrNodeArray: Node, renderMode: string): any;
502 | renderTemplate(template: Function, dataOrBindingContext: any, options: Object, targetNodeOrNodeArray: Node, renderMode: string): any;
503 | renderTemplate(template: any, dataOrBindingContext: any, options: Object, targetNodeOrNodeArray: Node, renderMode: string): any;
504 | renderTemplate(template: Function, dataOrBindingContext: KnockoutBindingContext, options: Object, targetNodeOrNodeArray: Node[], renderMode: string): any;
505 | renderTemplate(template: any, dataOrBindingContext: KnockoutBindingContext, options: Object, targetNodeOrNodeArray: Node[], renderMode: string): any;
506 | renderTemplate(template: Function, dataOrBindingContext: any, options: Object, targetNodeOrNodeArray: Node[], renderMode: string): any;
507 | renderTemplate(template: any, dataOrBindingContext: any, options: Object, targetNodeOrNodeArray: Node[], renderMode: string): any;
508 |
509 | renderTemplateForEach(template: Function, arrayOrObservableArray: any[], options: Object, targetNode: Node, parentBindingContext: KnockoutBindingContext): any;
510 | renderTemplateForEach(template: any, arrayOrObservableArray: any[], options: Object, targetNode: Node, parentBindingContext: KnockoutBindingContext): any;
511 | renderTemplateForEach(template: Function, arrayOrObservableArray: KnockoutObservable, options: Object, targetNode: Node, parentBindingContext: KnockoutBindingContext): any;
512 | renderTemplateForEach(template: any, arrayOrObservableArray: KnockoutObservable, options: Object, targetNode: Node, parentBindingContext: KnockoutBindingContext): any;
513 |
514 | expressionRewriting: {
515 | bindingRewriteValidators: any;
516 | parseObjectLiteral: { (objectLiteralString: string): any[] }
517 | };
518 |
519 | /////////////////////////////////
520 |
521 | bindingProvider: {
522 | instance: KnockoutBindingProvider;
523 | new (): KnockoutBindingProvider;
524 | }
525 |
526 | /////////////////////////////////
527 | // selectExtensions.js
528 | /////////////////////////////////
529 |
530 | selectExtensions: {
531 |
532 | readValue(element: HTMLElement): any;
533 |
534 | writeValue(element: HTMLElement, value: any): void;
535 | };
536 |
537 | components: KnockoutComponents;
538 | }
539 |
540 | interface KnockoutBindingProvider {
541 | nodeHasBindings(node: Node): boolean;
542 | getBindings(node: Node, bindingContext: KnockoutBindingContext): {};
543 | getBindingAccessors?(node: Node, bindingContext: KnockoutBindingContext): { [key: string]: string; };
544 | }
545 |
546 | interface KnockoutComputedContext {
547 | getDependenciesCount(): number;
548 | isInitial: () => boolean;
549 | isSleeping: boolean;
550 | }
551 |
552 | //
553 | // refactored types into a namespace to reduce global pollution
554 | // and used Union Types to simplify overloads (requires TypeScript 1.4)
555 | //
556 | declare module KnockoutComponentTypes {
557 |
558 | interface Config {
559 | viewModel?: ViewModelFunction | ViewModelSharedInstance | ViewModelFactoryFunction | AMDModule;
560 | template: string | Node[]| DocumentFragment | TemplateElement | AMDModule;
561 | synchronous?: boolean;
562 | }
563 |
564 | interface ComponentConfig {
565 | template: any;
566 | createViewModel?: any;
567 | }
568 |
569 | interface EmptyConfig {
570 | }
571 |
572 | // common AMD type
573 | interface AMDModule {
574 | require: string;
575 | }
576 |
577 | // viewmodel types
578 | interface ViewModelFunction {
579 | (params?: any): any;
580 | }
581 |
582 | interface ViewModelSharedInstance {
583 | instance: any;
584 | }
585 |
586 | interface ViewModelFactoryFunction {
587 | createViewModel: (params?: any, componentInfo?: ComponentInfo) => any;
588 | }
589 |
590 | interface ComponentInfo {
591 | element: Node;
592 | templateNodes: Node[];
593 | }
594 |
595 | interface TemplateElement {
596 | element: string | Node;
597 | }
598 |
599 | interface Loader {
600 | getConfig? (componentName: string, callback: (result: ComponentConfig) => void): void;
601 | loadComponent? (componentName: string, config: ComponentConfig, callback: (result: Definition) => void): void;
602 | loadTemplate? (componentName: string, templateConfig: any, callback: (result: Node[]) => void): void;
603 | loadViewModel? (componentName: string, viewModelConfig: any, callback: (result: any) => void): void;
604 | suppressLoaderExceptions?: boolean;
605 | }
606 |
607 | interface Definition {
608 | template: Node[];
609 | createViewModel? (params: any, options: { element: Node; }): any;
610 | }
611 | }
612 |
613 | interface KnockoutComponents {
614 | // overloads for register method:
615 | register(componentName: string, config: KnockoutComponentTypes.Config | KnockoutComponentTypes.EmptyConfig): void;
616 |
617 | isRegistered(componentName: string): boolean;
618 | unregister(componentName: string): void;
619 | get(componentName: string, callback: (definition: KnockoutComponentTypes.Definition) => void): void;
620 | clearCachedDefinition(componentName: string): void
621 | defaultLoader: KnockoutComponentTypes.Loader;
622 | loaders: KnockoutComponentTypes.Loader[];
623 | getComponentNameForNode(node: Node): string;
624 | }
625 |
626 | declare var ko: KnockoutStatic;
627 |
628 | declare module "knockout" {
629 | export default ko;
630 | }
631 |
--------------------------------------------------------------------------------