ActionStageSwift 0.2.0

ActionStageSwift 0.2.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布上次发布2018年9月
SPM支持 SPM

LawrenceHan 维护。



  • LawrenceHan

已弃用,请使用 SwiftActor

ActionStageSwift

ActionStage 的 Swift 版本。演员模型

入门指南

观察某些内容

ActionStage 可以观察一个路径(字符串),例如:ActionStageInstance.watchForPath("/myapp/tableview/hasnewcell", watcher: self)。您还可以观察通用路径:ActionStageInstance.watchForPath("/myapp/userdetail/@", @ 是标记。任何以 /myapp/userdetail 开头的路径都将触发代理。

分发资源

ActionStageInstance.dispatchResource(path: "/myapp/userdetail/(97172)", resource: text, arguments: nil)

处理已分发的资源

func actorCompleted(status: LHWActionStageStatus, path: String, result: Any?)
func actorReportedProgress(path: String, progress: Float)
func actionStageResourceDispatched(path: String, resource: Any?, arguments: Any?)
func actionStageActionRequested(_ action: String, options: Dictionary<String, Any>?)
func actorMessageReceived(path: String, messageType: String?, message: Any?)
func actionStageResourceDispatched(path: String, resource: Any?, arguments: Any?) {
    if path == "/myapp/userdetail/\(currentUserId)" {
        LHWDispatchOnMainThread {
            self.tableView.reloadData()
        }
    }
}

创建一个actor

import Foundation

class AddCellActor: LHWActor {
    
    override class func genericPath() -> String? {
        return "/myapp/userdetail/@" // Actor path
    }
    
    override func execute(options: [String: Any]?) {
        guard let options = options else {
            return
        }
        
        guard let text = options["text"] as? String else { // in this case we passed a string parameter to it
            return
        }
        
        // Do something
        something()
        
        // Dispatch resource or notify any watcher 
        ActionStageInstance.dispatchResource(path: path, resource: text, arguments: nil)
        
        // Tell wather this actor is done its job.
        DispatchQueue.global().asyncAfter(deadline: .now() + 0.1) {
            ActionStageInstance.actionCompleted(self.path)
        }
    }
    
    override func watcherJoined(watcherHandler: LHWHandler, options: [String : Any]?, waitingInActorQueue: Bool) {
        Logger.debug("joined handler: \(watcherHandler), options: \(options ?? [:]), path: \(path)")
    }
}

注册一个actor

LHWActor.registerActorClass(AddCellActor.self)

调用actor

func addCell() {
    let options = ["text": "new cell \(array.count+1)"]
    ActionStageInstance.requestActor(path: "/myapp/userdetail/(97172)", options: options, watcher: nil)
}

捐赠:也许给我买杯咖啡?

此项目受MIT许可证保护,基本上你可以随意使用它。

给我买杯咖啡无害,这样我可以花更多时间为大家带来更多好东西。

目前我只能在我个人时间(晚上、周末、假日)内从事开源项目。

Paypal

https://www.paypal.me/LawrenceGuangHan/

支付宝

https://github.com/LawrenceHan/ActionStageSwift/blob/master/payme.JPG