Skip to content

Instantly share code, notes, and snippets.

View borie88's full-sized avatar

George Borrelli borie88

  • Shanghai
View GitHub Profile
@borie88
borie88 / store.js
Created October 4, 2019 15:13
Mobx Store in WeChat Mini Program Project
import { observable, action } from 'mobx-miniprogram'
export const store = observable({
// state
counter: 0,
// actions
increment: action(function () {
this.counter++
}),
@borie88
borie88 / wxp.js
Created March 10, 2019 15:26
Wrap WeChat Mini Program APIs with a Promise
const methods = [
'getStorage',
'setStorage',
'getSystemInfo'
]
const wxp = {}
methods.forEach((method) => {
wxp[method] = (args = {}) =>
new Promise((resolve, reject) => {
args.success = (res) => resolve(res)
@borie88
borie88 / language.js
Last active March 10, 2019 15:34
Language handler for multilingual MP
import regeneratorRuntime from '../utils/runtime'
import wxp from '../utils/wxp'
import store from '../store'
// define our default locale here
const defaultLanguage = 'en'
// get any stored language settings from localStorage
const getStoredLanguage = async () => {
try {
@borie88
borie88 / strings.js
Created March 10, 2019 14:48
Strings for i18n Mini Program
export default {
en: {
loadingTitle: "Loading...",
helloThere: "Hello",
home: "Home",
profile: "Me"
},
zh: {
loadingTitle: "加载中...",
helloThere: "你好",
@borie88
borie88 / store.js
Last active March 10, 2019 15:09
Store.js for i18n Mini Program
import languageStrings from './i18n/strings'
export default {
data: {
language: 'en',
strings: languageStrings
},
getLanguage () {
return this.data.language
},