Giter Site home page Giter Site logo

bolt-rpc's Issues

cursor.update()の度にemitが走るが、データ取得が完了していない状態ならば待機状態に入るべき

  • APIの完了が遅い場合
  • データ取得条件の変更が短時間に連続で行われる場合

単体の問い合わせ処理を連続して行うと、処理完了が前後する可能性があります。

現在、cursor.update()を行うと、そのつど毎回問い合わせが発生しますが、問い合わせ完了まで次の問い合わせを行わないようにすることで、処理の前後を安定させた状態でtrackが可能になります。

  • cursor.update(a)
    • → update query(a), callAPI(a)
  • cursor.update(b)
    • → update query(b)
  • cursor.update(c)
    • → update query(c)
  • callAPI(a) done
    • → callback
    • → callAPI( c ) (update(b)はキャンセルされる)
  • callAPI(c) done
    • → callback

連続して呼び出すRead OnlyのAPIはtrack/cursorを基本とし、問い合わせ条件変更にupdateを使うことで、動作は安定します。

optionsの追加

dataはupdateされる可能性があるので、cursor作成時に紐付けるoptionsを追加する。
authに使う

再接続時にtrackを再登録する

socket.ioが再接続を行なった場合に、track状態が解除されてしまう。
再接続のイベントを拾って、再track状態に復帰する。

PromiseライクなクライアントAPI

元々のコールバックAPI

client.send 'add', {a: 1, b: 2}, (err, val) ->
  assert not err
  assert val is 3

PromiseライクAPI

cursor = client.send 'add', {a: 1, b: 2}
assert cursor.val is null # 初期値はnull
cursor.end (val) ->
# cursor.on 'end', (val) -> と同じ
  assert val is 3
  assert cursor.val is val
cursor.error (err) ->
# cursor.on 'error', (err) -> と同じ
  # エラーがあればここを通る
  assert cursor.err is err

updateができる

cursor.update({a: 2, b: 3})
cursor.end (val) ->
  assert val is 5

middleware

# {a: 1, b: 2} -> val = 3 のとき
cursor.map (val) ->
  return val * 2
cursor.map (val) ->
  return val - 1
cursor.end (val) ->
  assert val is 5

想定API

  • cursor.val
  • cursor.end((val)->)
  • cursor.error((err)->)
  • cursor.update(data)
  • cursor.map((val)->)

参考

https://github.com/component/emitter

vueでの使用例

var vm = new Vue({
    el: '#content',
    data: {
        lists: todo.get('find', {})
    }
})

trackではなくgetというvue向けに単純なオブジェクトのみを返すAPIを作りました.
理由はこちら : http://tech.nitoyon.com/ja/blog/2014/06/30/vue-js-hook/

仕様調整およびリファクタリング

expressのuseに似せているが、挙動が直感的でない部分が多いので、修正する

  • app.use 'module_name', subAppが自然に動くようにする
  • sub_name_spaceの廃止
  • track_pathをdelimiterで分解した最初のブロックをroomとする
    • track_path: '<key>.module.method'とすると、<key>がroom
    • track_pathのデフォルトはmethod名。明示的な指定もできるようにする
  • res.track()出来るようにする
  • メソッド実行後の自動trackをやめる
    • ほとんど使われていない機能
    • app.use {track: true}, (req, res) ->はexpress的な挙動で実装できてない
    • res.track()を明示的に呼ぶ方法に切り替え。middlewareでreq.end -> res.track()のようなこともできる

分散処理のサポート

フロントからのクエリを、そのまま登録メソッドにバインドする作りだが、マルチスレッドでの動作が不自由。

socketの段階ではメッセージベースでやりとりしているので、子プロセスに処理を分散する中間層を入れることはできるのではないか。

promisify

  • return promise if callback function isn't specified.
const {data} = await client.send(path, query, options);
...
  • auto cancel option with same parameters.
client.send(path, query, {autoCancel: true}, (err, data) => {
  //  if same path request is already called until this async callback.
  assert(err.message == 'AutoCancelled');
});

空のcursorを作りたい

# client = Client(xxx, xxx)
cur = client.track 'apiName'  # here
cur.error (err) ->
  console.log err

widget = Vue.extend
  data:
    conditions: {}
  watch:
    conditions: ->
      cur.update @conditions
  compiled: ->
    cur.end (data) ->
      # update widget view.

view = Vue.extend
  compiled: ->
    cur.end (data) ->
      # update view.

エラー時のハンドリング

サーバサイドでAPIのエラーログを取りたいとき、ハンドリングを行うための手段が用意されていません。

expressの仕様に似せて、下記の設定を行えるようにします。

app = new Server()
app.use 'api_name', (req, res, next) ->
  run (err, data) ->
    return next err if err
    res.json data

app.use (err, req, res, next) ->
  console.log err
  next()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.