Skip to content

Instantly share code, notes, and snippets.

@okunokentaro
Last active April 30, 2016 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save okunokentaro/f29547a529fc7bb7f9b0c2a25cb412ac to your computer and use it in GitHub Desktop.
Save okunokentaro/f29547a529fc7bb7f9b0c2a25cb412ac to your computer and use it in GitHub Desktop.
ng-kyoto Angular Meetup #4 資料
import Dexie from 'dexie';
const dbName = 'dexie-suburi';
const dbVer = 2;
window.indexedDB.deleteDatabase(dbName);
const dexieDb = new Dexie(dbName);
dexieDb.version(dbVer).stores({
user: '++id,name',
task: '++id,userId,text'
});
dexieDb.transaction('rw', [dexieDb.user, dexieDb.task], () => {
dexieDb.user.add({name: 'Jose'});
dexieDb.user.add({name: 'Michael'});
dexieDb.task.add({userId: 1, text: 'Buy milk'});
dexieDb.task.add({userId: 1, text: 'Buy egg'});
dexieDb.task.add({userId: 2, text: 'Visit a hospital'});
});
dexieDb.user
.each((user) => {
console.log(`Dexie user id: ${user.id} value: ${JSON.stringify(user)}`);
});
dexieDb.task
.each((task) => {
console.log(`Dexie task id: ${task.id} value: ${JSON.stringify(task)}`);
});
const dbName = 'indexeddb-suburi';
const dbVer = 1;
const idbReq = (() => {
window.indexedDB.deleteDatabase(dbName);
return window.indexedDB.open(dbName, dbVer);
})();
idbReq.onupgradeneeded = (ev) => {
const db = ev.target.result;
const userStore = db.createObjectStore('user', {keyPath: 'id'});
const taskStore = db.createObjectStore('task', {keyPath: 'id'});
}
idbReq.onsuccess = (ev) => {
const db = ev.target.result;
const transaction = db.transaction(['user', 'task'], 'readwrite');
const userStore = transaction.objectStore('user');
const taskStore = transaction.objectStore('task');
userStore.add({id: 1, name: 'Jose'});
userStore.add({id: 2, name: 'Michael'});
taskStore.add({id: 1, userId: 1, text: 'Buy milk'});
taskStore.add({id: 2, userId: 1, text: 'Buy egg'});
taskStore.add({id: 3, userId: 2, text: 'Visit a hospital'});
userStore.openCursor().onsuccess = (userStoreSuccessEv) => {
const cursor = userStoreSuccessEv.target.result;
if (cursor) {
console.log(`indexedDB user id: ${cursor.key} value: ${JSON.stringify(cursor.value)}`);
cursor.continue();
}
};
taskStore.openCursor().onsuccess = (taskStoreSuccessEv) => {
const cursor = taskStoreSuccessEv.target.result;
if (cursor) {
console.log(`indexedDB task id: ${cursor.key} value: ${JSON.stringify(cursor.value)}`);
cursor.continue();
}
};
};

Angular 2でアプリ作ってみた

armorik83

  • 奥野 賢太郎
    • 京都市出身
    • ChatWork株式会社
    • ng-kyoto代表, ng-japanスタッフ

スライドは?

  • 無い
    • 今日発表するアプリの実装に全ステータスを振った
    • すまん

話すこと

  • Angular 2ではどういうアーキテクチャがいいの?
  • Angular 2でFlux作ってみた
  • IndexedDBでアプリを作ってみた

Angular 2ではどういうアーキテクチャがいいの?

MVVMではない

どちらかというとMVC

  • Serviceに値を置いていって、DIしてその値を使う
    • Angular 1でいうSharedServiceの概念
    • MVCってあちこちでゴチャゴチャにデータフローが発生して煩雑だからFluxという一方向アーキテクチャが提唱されたのでは?

Flux

  • Angular 2はコンポーネント指向かつ高速
  • イベント中心に設計できる(正確に言うとRxJSによるstream)
    • Rxこじらせられる

Angular 2でFlux作ってみた

参考にした話

Redux

  • あれはReactのためのもの
    • React勢の中でもこじらせてる派閥のもの
    • なんかやけに話を複雑にしてそうで疑心暗鬼
      • みんな流行ってるという言葉だけで飛びついてない?
      • あれで多くのユースケース想定したときスケールしねぇ…って思ったんだけど私だけ?
  • とはいえ、詳しくないのでmizchiさんに聞いたら詳しいと思った

Savkin's Angular 2 Flux

Almin.js

Walts

  • Angular 2用Fluxフレームワークを作った
    • React用って腐るほどあるでしょ
    • Angular 2用もきっと腐るほど出るよ(もう出てる?知らない)
  • 自分の経験をベースにSavkin's FluxとAlmin.jsを参考にしている
  • もうちょい安定させたらOSS化
    • 自分がいろいろなアプリで使う用 && 晒し用
    • 入社8ヶ月の業務での知見と地雷経験がふんだんに活かされている
    • 何かの参考になれば

三拍子

  • View -> Action -> Store
  • ここからはコード見てもらったほうが早い

Demo

  • (よくあるincrementsの例を見せる)
  • (フレームワーク側の実装と、extendsの使用例を見せる)
    • (Viewからの発火)
    • (データフローと逆転のコールバックフロー)
    • (型保護とGenerics)
  • (incrementsのイベントを多重発火させたときの挙動を見せる)
  • (complete subjectの挙動を見せる)

IndexedDBでアプリを作ってみた

IndexedDB?

  • http://caniuse.com/#feat=indexeddb
  • Web SQLなんてなかった
  • オブジェクトに対する高速なインデックス処理と検索を可能にするローカルデータベース

Demo

  • (importのインタフェースをDirectiveで作った話を見せる)
  • (importを見せる)
  • (カテゴリの変更を見せる)
  • (ソースで解説)

他にいろいろハマったところ

  • ChangeDetectorRef
  • styles

アプリのソースコード

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment