我目前正在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) 我正在尝试使用该Perfect库在我的Ubuntu(Ubuntu 15.10 wily,Swift swift-3.0.1-RELEASE)上使用Swift创建一个应用程序.
我希望每X秒都有一个函数.为此,我正在使用模块的Timer类Foundation:
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)