Giter Site home page Giter Site logo

lotusoot's Introduction

Lotusoot

Lotusoot is a router tool and a decoupling tool of modular project.

中文介绍

Installtion

pod 'Lotusoot'

How to use

1. Configuration

  1. In Xcode: Click on your project in the file list, choose your target under TARGETS, click the Build Phases tab and add a New Run Script Phase by clicking the little plus icon in the top left
  2. Drag the new Run Script phase above the Compile Sources phase and below Check Pods Manifest.lock, expand it and paste the following script:

python ${PODS_ROOT}/Lotusoot/Lotusoot/Lotusoot.py ${SRC_ROOT} ${SRCROOT} Lotusoot
# parameter1: scan path
# parameter2: ${SRCROOT}, output path of Lotusoot.plist
# parameter3: suffix of Lotusoot(Can bes omited), Omit leads to script execution time
  1. Build your project, in Finder you will now see a Lotusoot.plist in the $SRCROOT-folder, add Lotusoot.plist into your project and uncheck Copy items if needed

Tip: Add the Lotusoot.plist to your .gitignore file to prevent unnecessary conflicts.

2. Use

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // register all routes
    LotusootCoordinator.registerAll()
    return true
}
  1. Call a service
let lotus = s(AccountLotus.self) 
let accountModule: AccountLotus = LotusootCoordinator.lotusoot(lotus: lotus) as! AccountLotus
accountModule.login(username: "admin", password: "wow") { (error) in
    print(error ?? "")
}
  1. Register a router
let error: NSError? = LotusootRouter.register(route: "newproj://account/login") { (lotusootURL) in
    accountModule.showLoginVC(username: "admin", password: "wow")
}
  1. Open an URL
let param: Dictionary = ["username" : "admin",
                                 "password" : "wow"]

// no call back                                 
LotusootRouter.open(route: "newproj://account/login", params: param)
// has call back
LotusootRouter.open(route: "newproj://account/login", params: param).completion { (error) in
    print(error ?? "open success")
}

// ⚠️Not recommanded, use ?pram0=xxx lead to mismanagement
// This method just for H5 page of Hybrid project
LotusootRouter.open(url: "newproj://account/login?username=zhoulingyu").completion { (error) in
    print(error ?? "open success")
}

3. Annotation and Suggest

Good usage example of Lotusoot

  1. Create Public module, where it defines Lotus protocol for all modules. A Lotus protocol defines all the functionality that open to other modules。For Example:
public protocol AccountLotus {
    func login(username: String, password: String, complete: (Error?) -> Void)
    func register(username: String, password: String, complete: (Error?) -> Void)
    func email(username: String) -> String
    func showLoginVC(username: String, password: String)
}
  1. Implement the Lotus protocol you have defined in Public Module, you can call it Lotusoot. In Lotusoot, you must add Annotation for current Lotusoot, include: NameSpace-@NameSpace, Lotusoot-@Lotusoot, Lotus-@Lotus:
// @NameSpace(TestAccountModule)
// @Lotusoot(AccountLotusoot)
// @Lotus(AccountLotus)
class AccountLotusoot: NSObject, AccountLotus {
    
    func email(username: String) -> String {
        return OtherService.email(username: "zhoulingyu")
    }

    func login(username: String, password: String, complete: (Error?) -> Void) {
        LoginService.login(username: username, password: password, complete: complete)
    }
    
    func register(username: String, password: String, complete: (Error?) -> Void) {
        RegisterService.register(username: username, password: password, complete: complete)
    }
    
    func showLoginVC(username: String, password: String) {
        print("show login view controller")
    }
}

Lotusoot MUST inherit from NSObject

  1. In your main project import Lotusootimport ModulePublic. You are free to call all the service and routers now

Tip: You can refer Demo -> NewProject

Demo

Demo 工程,Please do not forget build every Scheme first.

TO DO

  • Fetch router dynamically
  • Unified way of viewcontroller jump
  • Custom Animation

License

Lotusoot Use MIT License

lotusoot's People

Contributors

summertian4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lotusoot's Issues

route register

LotusootRouter.register(route: "newproj://account/login"), 路由的注册时机,在oc里面也是要在load方法里面吧,swift在哪调用呢? 如果不提前注册,open方法就失效了

Lotusoot.plist内容为空

我自己新建了一个项目,将demo中ZLYAccountModule模块pod进去MainLotus.swift和MainLotusoot.swift拖进我的项目,中间件Lotusoot 是pod 进去,按照步骤配置,build,生成了Lotusoot.plist文件,但是Lotusoot.plist文件中没有数据,这是为什么呢?

关于框架的一些建议

为什么不考虑使用OC来作为框架的开发语言呢,OC有强大的Runtime方法,又能同时给OC开发者和Swift开发者使用,不会随新版Swift语法的变动而变动,另外我认为约定优于配置会更好

是否有纯oc版本的

从博客看了过来的,正好在做私有库组件化。是否有纯oc版本的呢?公司接受不了混编的风险

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.