Upgrade to Pro — share decks privately, control downloads, hide ads and more …

オフラインファーストなアプリケーション開発

358791a9c91e7615ffe62c7c6e02e470?s=47 zaki50
March 09, 2017

 オフラインファーストなアプリケーション開発

DroidKaigi 2017 Day1
16:00-16:50 Room 3

358791a9c91e7615ffe62c7c6e02e470?s=128

zaki50

March 09, 2017
Tweet

Transcript

  1. my@realm.io ΦϑϥΠϯϑΝʔετ ΞϓϦέʔγϣϯ։ൃ 2017/3/9 Droid Kaigi 2017 16:00- Room3 Makoto

    Yamazaki (@zaki50)
  2. my@realm.io Makoto Yamazaki Realm / uPhyca Inc. @zaki50

  3. my@realm.io agenda ΦϑϥΠϯϑΝʔετͱ͸ ΦϑϥΠϯϑΝʔετͰͷٕज़త՝୊ Realmతղܾࡦ σϞ ·ͱΊ

  4. my@realm.io ΦϑϥΠϯϑΝʔ ετʁ

  5. my@realm.io ΦϑϥΠϯϑΝʔετ ݩʑ͸WebͰͷߟ͑ํ ࠷ॳ͔ΒΦϑϥΠϯͰͷಈ࡞Λߟ͑ͨWebαʔϏε ϒϥ΢β͕ϩʔΧϧʹετϨʔδΛ࣋ͯΔΑ͏ʹͳͬ ͨ

  6. my@realm.io ϞόΠϧ Billions of Minutes Online (USA) 0 250 500

    750 1000 1250 1500 Jun 2013 Jun 2014 Jun 2015 Desktop Mobile App Mobile Browser
  7. my@realm.io ϞόΠϧͰͷΦϑϥΠϯϑΝʔετ αʔϏεΛ੒ޭͤ͞ΔͨΊʹ͸ྑ͍ΞϓϦ͕ඞཁ ΦϑϥΠϯͰͷར༻͸ίΞػೳ ར༻ऀ͸ΦϑϥΠϯͰ࢖͑Δ͜ͱΛ౰ͨΓલͱࢥ͍࢝ Ίͨ

  8. my@realm.io ඞཁͳػೳ αʔόʔͱͷ௨৴ ΦϑϥΠϯ࣌ͷͨΊͷετϨʔδʗσʔλϕʔε ΦϯϥΠϯʹͳͬͨ࣌ͷσʔλಉظ ͜ΕΒ͕ࣗવͳܗͰΞϓϦͷػೳʹ૊Έࠐ·Ε͍ͯΔ͜ͱ

  9. my@realm.io ௨৴෦෼ͷ՝୊ Java, React Native, Xamarin σʔλϕʔε ௨৴ʗσʔλಉظػೳ Android

  10. my@realm.io ௨৴ͷ՝୊

  11. my@realm.io σʔλϕʔεͷ՝୊ ΦϑϥΠϯ࣌༻ͷϩδοΫΛผ్࣮૷͢ Δ͜ͱ͕ඞཁ ΦϯϥΠϯ࣌: αʔόʔ͔Βऔಘ(ͱอଘ) ΦϑϥΠϯ࣌: σʔλϕʔε͔Βऔಘ

  12. my@realm.io ಉظͷ՝୊ ࠷৽৘ใͷऔಘλΠϛϯά ΦϯϥΠϯʹͳͬͨΒࡍͷΞοϓϩʔυ ෳ਺୺຤Ͱͷมߋͷ౷߹ ਖ਼௚ͱͯ΋೉͍͠

  13. my@realm.io Realm Mobile Platform͕ղܾ͠·͢

  14. my@realm.io Realm Mobile Platform ෳ਺σόΠεͷσʔλϕʔεΛϦΞϧλΠϜಉظ ΦϑϥΠϯͰ΋ϩʔΧϧͷσʔλϕʔε͕࢖͑Δ ΦϑϥΠϯ࣌ͷมߋিಥΛࣗಈղܾ SD SD SD

    SDK SD Object Store Sync
 Server RMP Dashboar d Event Auth System Encryption Layer Rules Engine Data Connect ors Real-time Sync
  15. my@realm.io RMPͰͷ௨৴ߏ੒ Java, React Native, Xamarin σʔλϕʔε ௨৴ʗσʔλಉظػೳ Android

  16. my@realm.io ୯ͳΔಉظҎ্ͷ࢖͍ํ

  17. my@realm.io Realm Mobile Database

  18. Ϟσϧͷఆٛ my@realm.io public class Task extends RealmObject { @PrimaryKey public

    String id = UUID.randomUUID().toString(); @Required
 public Date createdAt = new Date();
 
 public String text;
 public boolean completed; }
  19. RealmΠϯελϯεͷऔಘ my@realm.io Realm realm = Realm.getDefaultInstance(); // 様々な機能へアクセスするための入り口。 // データベースコネクションと捉えることも可能。

    ... // 終わったら忘れずに閉じる realm.close();

  20. σʔλͷૠೖ my@realm.io final Task task = new Task();
 task.text =

    "原稿を書く"; realm.executeTransactionAsync(new Realm.Transaction() {
 @Override
 public void execute(Realm realm) {
 realm.insert(task);
 }
 });
  21. σʔλͷݕࡧͱ஋΁ͷΞΫηε my@realm.io final RealmResults<Task> completedTasks = realm.where(Task.class)
 .equalTo("completed", true) .findAll();


    for (Task completedTask : completedTasks) {
 Log.d("debug", completedTask.text);
 }

  22. σʔλͷߋ৽ my@realm.io RealmResults<Task> allTasks = realm.where(Task.class) .findAllSorted("createdAt"); // たとえばリストで position

    == 5 の要素がタップされた時 final Task task = allTasks.get(5); 
 realm.executeTransaction(new Realm.Transaction() {
 @Override
 public void execute(Realm realm) { task.completed = true; }
 });
  23. σʔλͷ࡟আ my@realm.io RealmResults<Task> allTasks = realm.where(Task.class) .findAllSorted("createdAt"); // たとえばリストで position

    == 5 の要素がスワイプされた時 final Task task = allTasks.get(5); 
 realm.executeTransaction(new Realm.Transaction() {
 @Override
 public void execute(Realm realm) { task.deleteFromRealm(); }
 });
  24. มߋ௨஌ my@realm.io completedTasks.addChangeListener(
 new OrderedRealmCollectionChangeListener<RealmResults<Task>>() {
 @Override
 public void onChange(RealmResults<Task>

    tasks,
 OrderedCollectionChangeSet changeSet) {
 // changeSetから、追加/削除/更新があった要素を取得 可能
 }
 });
  25. Realmͷ࢖͍ํ·ͱΊ my@realm.io • Ϋϥεͱͯ͠ϞσϧΛఆٛ͢Δ • RealmΠϯελϯεΛऔಘ͢Δ • τϥϯβΫγϣϯͷதͰ௥Ճ΍ߋ৽Λߦ͏ • ݕࡧΛߦ͍ɺදࣔʹඞཁͳΦϒδΣΫτΛRealmResults΍ݸผͷ

    ϞσϧΦϒδΣΫτͱͯ͠औಘ͢Δ • RealmResults΍ϞσϧΦϒδΣΫτʹηοτͨ͠ϦεφʔͰ࠷৽ ͷ৘ใΛड͚औΓදࣔ͢Δ
  26. ͦͷଞͷಛ௃ my@realm.io • ߴ଎ • ஗Ԇϩʔυ • σʔλϕʔε҉߸Խ • ΫϩεϓϥοτϑΥʔϜ(Android,

    iOS) • etc.
  27. ηοτΞοϓ my@realm.io // in build.gradle buildscript { repositories { jcenter()

    } dependencies { classpath "io.realm:realm-gradle-plugin:3.0.0" } } // in app/build.gradle apply plugin: 'realm-android'
  28. my@realm.io σʔλಉظ΁ͷࣗવͳ֦ு

  29. σʔλͷߋ৽ my@realm.io RealmResults<Task> allTasks = realm.where(Task.class) .findAllSorted("createdAt"); // たとえばリストで position

    == 5 の要素がタップされた時 final Task task = allTasks.get(5); 
 realm.executeTransaction(new Realm.Transaction() {
 @Override
 public void execute(Realm realm) { task.completed = true; }
 });
  30. มߋ௨஌ my@realm.io completedTasks.addChangeListener(
 new OrderedRealmCollectionChangeListener<RealmResults<Task>>() {
 @Override
 public void onChange(RealmResults<Task>

    tasks,
 OrderedCollectionChangeSet changeSet) {
 // changeSetから、追加/削除/更新があった要素を取得可能
 }
 });
  31. σʔλͷߋ৽ my@realm.io Server-side Realms completed = true; completed = true;

    onChange()
  32. ϩάΠϯ my@realm.io // 認証 SyncCredentials credential = SyncCredentials.usernamePassword(email, password, false);


    SyncUser user = SyncUser.login(credential, RealmTasksApplication.AUTH_URL);
 SyncConfiguration defaultConfig = new SyncConfiguration.Builder(user, RealmTasksApplication.REALM_URL) .build();
 Realm.setDefaultConfiguration(defaultConfig);
  33. my@realm.io Demo

  34. my@realm.io িಥղܾ

  35. ඪ४ͷղܾϧʔϧ my@realm.io ࡟আ͸ৗʹ༏ઌ͞ΕΔ ಉ͡ϓϩύςΟͷฤू͸ޙউͪ Ϧετ΁ͷૠೖ͸࣌ؒॱ Operational TransformʹΑΓɺ֤୺຤ʹద੾ͳ มߋηοτ͕഑෍͞ΕΔ

  36. my@realm.io CAPఆཧ ConsistencyʢҰ؏ੑʣ AvailabilityʢՄ༻ੑʣ Partition Toleranceʢ෼அ଱ੑʣ ̎ͭ·Ͱ͔͠ಉ࣌ʹຬͨ͢͜ͱ͕Ͱ͖ͳ͍

  37. my@realm.io CAPఆཧ ConsistencyʢҰ؏ੑʣ AvailabilityʢՄ༻ੑʣ Partition Toleranceʢ෼அ଱ੑʣ ҰൠతͳRDB

  38. my@realm.io CAPఆཧ ConsistencyʢҰ؏ੑʣ AvailabilityʢՄ༻ੑʣ Partition Toleranceʢ෼அ଱ੑʣ Apache HBaseɺMongoDB

  39. my@realm.io CAPఆཧ ConsistencyʢҰ؏ੑʣ AvailabilityʢՄ༻ੑʣ Partition Toleranceʢ෼அ଱ੑʣ DNSͳͲɻRealm Mobile Platform΋͜Ε

  40. my@realm.io Eventual Consistency Strong Eventual Consistency Strong Consistency Ұ؏ੑ

  41. my@realm.io ·ͱΊ

  42. my@realm.io ௨৴ͷ໰୊ σʔλϕʔεͷ໰୊ ಉظͷ໰୊ ೉͍͜͠ͱ͸RMPʹ·͔ͤΑ͏

  43. ࢀߟ৘ใ my@realm.io realm.io