Skip to content

Commit

Permalink
Add request config options param. Updates to pass new linting rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
spacejack committed Sep 11, 2017
1 parent f55209d commit d449dd4
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 126 deletions.
6 changes: 3 additions & 3 deletions types/mithril/index.d.ts
Expand Up @@ -21,9 +21,9 @@ declare function request <T>(options: Mithril.RequestOptions<T> & { url: string
declare function request <T>(url: string, options?: Mithril.RequestOptions<T>): Promise<T>;

/** Makes a JSON-P request and returns a promise. */
declare function jsonp<T>(options: Mithril.JsonpOptions & { url: string }): Promise<T>;
declare function jsonp<T>(options: Mithril.JsonpOptions & { url: string }): Promise<T>; // tslint:disable-line:no-unnecessary-generics
/** Makes a JSON-P request and returns a promise. */
declare function jsonp<T>(url: string, options?: Mithril.JsonpOptions): Promise<T>;
declare function jsonp<T>(url: string, options?: Mithril.JsonpOptions): Promise<T>; // tslint:disable-line:no-unnecessary-generics

/** Creates an event handler which takes the value of the specified DOM element property and calls a function with it as the argument. */
declare function withAttr(name: string, callback: (value: any) => any): (e: { currentTarget: any, [p: string]: any }) => void;
Expand Down Expand Up @@ -116,7 +116,7 @@ declare namespace Mithril {
/** Whether to send cookies to 3rd party domains. */
withCredentials?: boolean;
/** Exposes the underlying XMLHttpRequest object for low-level configuration. */
config?(xhr: XMLHttpRequest): XMLHttpRequest | void;
config?(xhr: XMLHttpRequest, options: this): XMLHttpRequest | void;
/** Headers to append to the request before sending it. */
headers?: { [key: string]: string };
/** A constructor to be applied to each object in the response. */
Expand Down
2 changes: 1 addition & 1 deletion types/mithril/test/test-api.ts
Expand Up @@ -20,7 +20,7 @@ const FRAME_BUDGET = 100;
{
const vnode = m.fragment({key: 123}, [m("div")]);
console.assert((vnode.children as Array<m.Vnode<any, any>>).length === 1);
console.assert(vnode.children![0].tag === 'div');
console.assert((vnode.children as Array<m.Vnode<any, any>>)[0].tag === 'div');
}

{
Expand Down
2 changes: 1 addition & 1 deletion types/mithril/test/test-component.ts
Expand Up @@ -50,7 +50,7 @@ const comp2: Component<Comp2Attrs, {}> = {
m(comp2, {title: '', description: ''});

// Correct use with lifecycle method
m(comp2, {title: '', description: '', oncreate: (v) => v.attrs.title + '\n' + v.attrs.description});
m(comp2, {title: '', description: '', oncreate: (v) => `${v.attrs.title}\n${v.attrs.description}`});

// Properties missing
// $ExpectError
Expand Down
3 changes: 2 additions & 1 deletion types/mithril/test/test-request.ts
Expand Up @@ -44,8 +44,9 @@ request<Result>('/id', {
});

request<Result>('/item', {
config: xhr => {
config: (xhr, opts) => {
xhr.setRequestHeader('accept', '*');
console.log(opts.background);
return xhr;
},
headers: {"Content-Type": "application/json"},
Expand Down
117 changes: 0 additions & 117 deletions types/mithril/test/test-stream.ts
Expand Up @@ -134,17 +134,6 @@ import { Stream } from 'mithril/stream';
console.assert(b()() === undefined);
}

{
let count = 0;
const a = stream(1);
const b = stream.combine(a => stream.HALT, [a])
["fantasy-land/map"](() => {
count++;
return 1;
});
console.assert(b() === undefined);
}

{
const all = stream.merge([
stream(10),
Expand Down Expand Up @@ -215,112 +204,6 @@ import { Stream } from 'mithril/stream';
console.assert(doubled() === 4);
}

{
const s = stream<number>();
const doubled = s["fantasy-land/map"]((n: number) => n * 2);
s(3);
console.assert(doubled() === 6);
}

{
const s = stream(3);
const doubled = s["fantasy-land/map"]((n: number) => n * 2);
console.assert(doubled() === 6);
}

{
const s = stream<undefined>();
const mapped = s["fantasy-land/map"](String);
s(undefined);
console.assert(mapped() === "undefined");
}

{
const s = stream(undefined);
const mapped = s["fantasy-land/map"](String);
console.assert(mapped() === "undefined");
}

{
const s = stream(undefined);
const mapped = s["fantasy-land/map"]((_value: undefined) => stream());
console.assert(mapped()() === undefined);
}

{
const s = stream(undefined);
console.assert(s["fantasy-land/map"] === s.map);
}

{
const apply = stream((n: number) => n * 2);
const s = stream(3);
const applied = s["fantasy-land/ap"](apply);
console.assert(applied() === 6);
apply(n => n / 3);
console.assert(applied() === 1);
s(9);
console.assert(applied() === 3);
}

{
const apply = stream<(value: undefined) => string>(String);
const s = stream(undefined);
const applied = s["fantasy-land/ap"](apply);
console.assert(applied() === "undefined");
apply(value => String(value) + "a");
console.assert(applied() === "undefineda");
}

{
const s = stream(3);
const mapped = s["fantasy-land/map"]((v: number) => v);
console.assert(s() === mapped());
}

{
const f = (x: number) => x * 2;
const g = (x: number) => x * x;
const s = stream(3);
const mapped = s["fantasy-land/map"]((value: any) => f(g(value)));
const composed = s["fantasy-land/map"](g)["fantasy-land/map"](f);
console.assert(mapped() === 18);
console.assert(mapped() === composed());
}

{
const a = stream((n: number) => n * 2);
const u = stream((n: number) => n * 3);
const v = stream(5);
const mapped = v["fantasy-land/ap"](u["fantasy-land/ap"](a["fantasy-land/map"]((f: any) => (g: any) => (x: any) => f(g(x)))));
const composed = v["fantasy-land/ap"](u)["fantasy-land/ap"](a);
console.assert(mapped() === 30);
console.assert(mapped() === composed());
}

{
const a = stream()["fantasy-land/of"]((value: number) => value);
const v = stream(5);
console.assert(v["fantasy-land/ap"](a)() === 5);
console.assert(v["fantasy-land/ap"](a)() === v());
}

{
const a = stream(0);
const f = (n: number) => n * 2;
const x = 3;
console.assert(a["fantasy-land/of"](x)["fantasy-land/ap"](a["fantasy-land/of"](f))() === 6);
console.assert(a["fantasy-land/of"](x)["fantasy-land/ap"](a["fantasy-land/of"](f))() === a["fantasy-land/of"](f(x))());
}

{
const u = stream((n: number) => n * 2);
const a = stream();
const y = 3;
console.assert(a["fantasy-land/of"](y)["fantasy-land/ap"](u)() === 6);
console.assert(a["fantasy-land/of"](y)["fantasy-land/ap"](u)() === u["fantasy-land/ap"](a["fantasy-land/of"]((f: any) => f(y)))());
}

// scan

{
Expand Down
3 changes: 1 addition & 2 deletions types/mithril/tsconfig.json
Expand Up @@ -5,9 +5,8 @@
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": []
Expand Down
1 change: 0 additions & 1 deletion types/mithril/tslint.json
Expand Up @@ -3,7 +3,6 @@
"rules": {
// TODOs
"no-duplicate-imports": false,
"object-literal-key-quotes": false,
"no-empty-interface": false
}
}

0 comments on commit d449dd4

Please sign in to comment.