野狗與微信小程序的結合

wilddog-weapp

野狗(wilddog)微信小程序客戶端 (preview)html

注意:git

  • 因爲微信沒有正式公開小程序,因此此版本爲預覽版,請不要用於正式生產環境github

已知問題:web

  • 在微信開發者工具中會出現必定機率的不能鏈接野狗服務器現象小程序

  • 目前只支持數據同步部分功能,auth和用戶管理相關功能並無作支持微信小程序

項目地址

https://github.com/WildDogTea...api

引入野狗客戶端

  1. 將wilddog-weapp-all.js 直接放到微信小程序的項目中服務器

  2. 使用commonjs引入微信

var wilddog = require('wilddog-weapp-all')
  1. 初始化微信開發

var config = {
    syncURL:<your-app-url>
}
wilddog.initializeApp(config)
  1. 使用 ononce,set,push,update 等API進行數據同步操做。

好比:

var ref = wilddog.sync().ref('demo')

ref.on('child_changed',(snapshot) => {
  var value = snapshot.val()
  console.log(value)
})

ref.on('child_changed',(snapshot) => {
  //you code
})

ref.orderByPriority().limitToFirst(100).once('value',(snapshot)=>{
    var key = snapshot.key()
    var value = snapshot.val()
})
ref.child('abc').set(123)

ref.child('abc').push('hello world',function(err){
    if(err){
        //sync to cloud with error
    }
    else{
        //OK!
    }
})

具體參考 https://docs.wilddog.com/api/...
支持 Wilddog.sync 下全部的API

DEMO

目前只寫了一個粗糙的demo
https://github.com/stackOverM...

contribute

很是歡迎各類形式的issue,和代碼。

原文地址 http://jack-x.engineer/2016/1...

相關文章
相關標籤/搜索