Giter Club home page Giter Club logo

Comments (2)

iohao avatar iohao commented on July 17, 2024

自定义 FlowContext
开发者可以自定义 FlowContext 方便做一些方法上的扩展,这些定制可以更好的服务于开发者的项目;业务框架新增 FlowContextFactory 业务框架 flow 上下文工厂,用于创建自定义的 FlowContext。通常使用自定义的 FlowContext,一般用于为 FlowContext 添加上一些方法;

框架默认提供的 FlowContext 已经将 invokeXXX 系列方法给标记为 Deprecated ,因为这是前期的一个 API 错误设计,invokeXXX 系列方法严格来说不算是 FlowContext 的职责;但在实际的业务开发中,开发者自定义的 FlowContext 是可以这么做的;

对于更详细的描述与具体使用,可以参考 https://www.yuque.com/iohao/game/zz8xiz#sLySn 在线文档

from iogame.

iohao avatar iohao commented on July 17, 2024

使用示例
在业务框架中,添加自定义的 FlowContextFactory 生产工厂

@UtilityClass
public class MyBarSkeletonConfig {
    public BarSkeleton createBarSkeleton() {
        BarSkeletonBuilderParamConfig config = new BarSkeletonBuilderParamConfig();

        BarSkeletonBuilder builder = config.createBuilder()
                // 设置一个自定义的 flow 上下文生产工厂
                .setFlowContextFactory(MyFlowContext::new);

        return builder.build();
    }
}

MyFlowContext 是 FlowContext 子类,我们在 MyFlowContext 中添加了一个自定义的方法 (hello)。

public class MyFlowContext extends FlowContext {
    public String hello() {
        return "MyFlowContext hello";
    }
}

在 action 中的使用
自定义的 FlowContext (MyFlowContext)与框架默认提供的 FlowContext 使用方式是一样的

@ActionController(SchoolCmdModule.cmd)
public class SchoolAction {
    /**
     * 请求、响应
     *
     * @param logicRequestPb logicRequestPb
     * @return LogicRequestPb
     */
    @ActionMethod(SchoolCmdModule.here)
    public LogicRequestPb here(LogicRequestPb logicRequestPb, MyFlowContext myFlowContext) {

        log.info("my flowContext : {}", myFlowContext.getClass());
        myFlowContext.hello();

        LogicRequestPb newLogicRequestPb = new LogicRequestPb();
        newLogicRequestPb.name =  "MyFlowContext, I'm here ";

        return newLogicRequestPb;
    }
}

from iogame.

Related Issues (20)

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.