小编Aur*_*ret的帖子

VueX:如何使用嵌套对象构建商店

我目前正在VueJS(尤其是Vuex)中编码应用程序。但是,我的问题与该库的联系并不紧密,而是与flux / redux / Vuex这样的商店拥有的体系结构紧密相关。

简单来说,我有几个API(每个团队一个API /数据库),每个团队/ API有几个用户,这些团队和用户由简单的对象表示,每个都有自己的子对象。重要说明:团队的成员当然是唯一的,但是团队的用户对于他们自己的团队而言是唯一的。用户的唯一性约束将为“ teamSlug / userSlug”。考虑到大量用户,我不能简单地加载所有团队的所有用户。

我的问题是如何正确构造我的应用程序/存储,以恢复给定用户数据块(与他的团队)的数据:如果我尚未加载此用户,请发出API请求以对其进行检索。当前,我已经创建了一个返回用户对象的吸气剂,该对象从用户和团队中获得了胜利。如果返回“ null”或带有“ .loading”到“ false”,我必须运行“ loadOne”动作,该动作将负责检索它:

import * as types from '../../mutation-types'
import users from '../../../api/users'

// initial state
const state = {
  users: {}
}

// getters
const getters = {
  getOne: state => (team, slug) => (state.users[team] || {})[slug] || null
}

// actions
const actions = {
  loadOne ({ commit, state }, { team, slug }) {
    commit(types.TEAM_USER_REQUEST, { team, slug })
    users.getOne(team, slug)
      .then(data => commit(types.TEAM_USER_SUCCESS, …
Run Code Online (Sandbox Code Playgroud)

javascript flux redux vuex vuejs2

5
推荐指数
1
解决办法
539
查看次数

Swift 3 Linux with Perfect:在runLoop中添加一个带间隔的预定计时器

我正在尝试使用该Perfect在我的Ubuntu(Ubuntu 15.10 wily,Swift swift-3.0.1-RELEASE)上使用Swift创建一个应用程序.

我希望每X秒都有一个函数.为此,我正在使用模块TimerFoundation:

class MyTimer {
    init() {
        var timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(MyTimer.onTimer(timer:)), userInfo: nil, repeats: true)
    }
    @objc func onTimer(timer: Timer) {
        print("MyTimer.onTimer")
    }
}
Run Code Online (Sandbox Code Playgroud)

尽管使用此代码找到了几个解决方案,但编译失败了:

$> swift build
Compile Swift Module 'my-app' (7 sources)
/home/.../Sources/MyTimer.swift:8:16: error: method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C
    @objc func onTimer(timer: Timer) {
Run Code Online (Sandbox Code Playgroud)

如果我正在扩展我的类NSObject或者如果我删除了参数,则会出现另一个编译错误timer:

$> …
Run Code Online (Sandbox Code Playgroud)

timer nsrunloop swift perfect swift3

4
推荐指数
1
解决办法
896
查看次数

标签 统计

flux ×1

javascript ×1

nsrunloop ×1

perfect ×1

redux ×1

swift ×1

swift3 ×1

timer ×1

vuejs2 ×1

vuex ×1