This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 指定したミリ秒後にresolveするPromiseを返す | |
| function resolveAsync<TValue>(value: TValue, timeout: number): Promise<TValue> { | |
| return new Promise<TValue>((resolve, reject) => { | |
| setTimeout(() => { | |
| console.timeStamp(`resolve: ${value}`); | |
| resolve(value); | |
| }, timeout); | |
| }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // fetchを使ってjsonを読み込む | |
| const testAsync = async () => { | |
| const response = await fetch("sample.json"); | |
| // sample.json | |
| // { "message": "Hello, World!" } | |
| const json: { message: string; } = await response.json(); | |
| console.log(json.message); | |
| // Hello, World! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as Rx from "@reactivex/rxjs"; | |
| // doオペレータで値の流れを確認 | |
| Rx.Observable.of(1, 2, 3) | |
| .do(value => console.log(`do[of]: (value: ${value})`)) | |
| .filter(value => value % 2 == 0) | |
| .do(value => console.log(`do[filtered]: (value: ${value})`)) | |
| .map(value => value * 2) | |
| .do(value => console.log(`do[mapped]: (value: ${value})`)) | |
| .subscribe( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // async/awaitとPromiseのサンプル | |
| // Promiseを返す関数 | |
| const actionAsync = (result: number) => { | |
| const promise = new Promise<number>((resolve, reject) => { | |
| // 1秒後にresolveする | |
| setTimeout(() => resolve(result), 1000); | |
| }); | |
| return promise; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as Rx from "@reactivex/rxjs"; | |
| // scan | |
| // 都度nextコールバックが呼ばれる | |
| Rx.Observable.of(1, 2, 3) | |
| .scan((acc, value, index) => acc + value) | |
| .subscribe( | |
| value => console.log(`next: (value: ${value})`), | |
| error => console.log(`error: ${error}`), | |
| () => console.log(`complete:`)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Promise | |
| // resolveとrejectは関数 | |
| const promise = new Promise((resolve, reject) => { | |
| // 3秒後にresolveする | |
| setTimeout(() => resolve(1), 3000); | |
| }); | |
| // resolveされたときのコールバック | |
| promise.then(value => console.log(value)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta name="viewport" content="width=device-width" /> | |
| <title>flexbox</title> | |
| <style> | |
| *, | |
| ::before, | |
| ::after { | |
| box-sizing: inherit; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // thenメソッド(doneFilter)を使うと、 | |
| // resolveされたときにフィルタできる | |
| $(() => { | |
| const deferred = $.Deferred<number>(); | |
| deferred.promise().then(value => { | |
| // resolveメソッドに渡した引数をコールバックで取得できる | |
| console.log(`then: ${value}`); | |
| return value * value; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use Test; | |
| begin tran; | |
| -- テーブル作成 | |
| drop table if exists dbo.Monster; | |
| create table dbo.Monster( | |
| Id int, | |
| Name nvarchar(20) not null, | |
| Version rowversion not null, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use Test; | |
| begin tran; | |
| -- テーブル作成 | |
| drop table if exists dbo.Character; | |
| create table dbo.Character( | |
| Id int, | |
| Name nvarchar(4) not null, | |
| Level int not null, |