Code Monkey home page Code Monkey logo

Comments (8)

lifesinger avatar lifesinger commented on June 9, 2024

没懂

模块化后,应该比以前更容易定位到问题所在,并快速做出处理。

from aralejs.github.io.

popomore avatar popomore commented on June 9, 2024

是由发布流程决定的,我们代码上线需要一定的流程才能上线。现在如果代码有问题,通过cms实时发布一段代码暂时解决问题。以后可能会把cms作为正常的修复方式,所以我们要提供一个如何修复的方案,如果有可以给个最佳实践的文档。

from aralejs.github.io.

lifesinger avatar lifesinger commented on June 9, 2024

这个可以,支持等一定阶段的时候,梳理出一份最佳实践
并且有可能在这点上大幅提升体验

from aralejs.github.io.

leoner avatar leoner commented on June 9, 2024

这个在以前实现自己的那个加载器的时候就想过类似的问题啊, 下面是我的一点想法. 供大家参考

这类问题基本上有两类需求

  1. 就是上面提到的, 如果我们有一个模块有问题, 但是由于我们的模块基本上对外暴露的都是api, 也可以认为是某个方法有问题, 所以如果我们能把这个方法动态的进行替换, 基本上就能解决上面的这个问题了.
  2. 另一个和这个类似, 比如有这样一个需求. 如果我们在某一个项目需要对所有的ajax的get请求增加一个参数. 那么这种情况其实也可以认为对这个方法进行增强.

对应这两个方案可以有下面基本的处理方式

  1. proxy, : 我们可以对指定的模块(这个模块是还没有加载或者加载还没有被执行)中增加代理功能, 这样我们就可以在proxy增加逻辑对模块中的所有方法进行拦截(AOP), 如果没有问题的方法, 我们正常调用原有模块的方法, 但是如果有问题的我们可以把这个方法的请求到代理模块上进行代码修正的方法.
  2. 装饰 or filter. 我们可以对模块的方法中增加decorate. 我们可以在装饰代码中执行一定的逻辑后, 在继续转调实际的方法即可. 或者我们可以支持对方法增加参数增过滤器等, 经过过滤的参数才能被传递给实际方法.

如何发布呢?

  1. 简单的方式就可以通过cms. 这样我们在页面的头部, 把我们hack的代码提前加载进来, 这样当实际模块加载和执行的时候这些hack代码就可以生效了.

from aralejs.github.io.

popomore avatar popomore commented on June 9, 2024

关于如何发布?

我们可以提供一整套cms的修复方案,除了康辉刚才说的还可以控制hack范围,比如只处理某一个页面或一个系统。
这样有助于我们的hack代码的管理

如何处理

我们可以在出口做拦截,require的时候对返回对象进行替换,可以替换对象或者方法。
拦截的代码也可以场景判断,比如要触发这个hack才去load拦截的代码,一般场景是用不到的。

from aralejs.github.io.

leoner avatar leoner commented on June 9, 2024

恩, 比如可以这样

seajs.proxy('arale.base-2.0-SNAPSHOT', function(exports, module) {
     export.get = function() {console.log('禁止使用!');}
});

我们可以给某一个模块绑定一个代理, 然后在这个代理函数中可以在用户使用之前获取exports, module. 然后这个代理就有机会在用户使用这个模块之前, 对模块进行替换或者增强等.

然后类似下面的代码, 我们可以在用户require模块的时候, 在返回exports之前, 去检查代理, 发现有的话, 可以去执行代理.

var proxys = mod.proxys;
var proxy;
while(proxy = proxys.shift()) {
     proxy.call(mod, exports, mod); 
}
return mod.exports;

from aralejs.github.io.

popomore avatar popomore commented on June 9, 2024

我期望是通过配置来实现

seajs.config({
    bugfix:{
        'arale.base-2.0-SNAPSHOT', function(exports, module) {
             export.get = function() {console.log('禁止使用!');}
        }
    }
}

如果require了arale.base,则同时require proxy。在callback执行前调用bugfix里的function,类似一个filter的功能。

这样可以把proxy和其他模块解耦合,还能按需加载,不让proxy影响到其他模块。

from aralejs.github.io.

lifesinger avatar lifesinger commented on June 9, 2024

整理了一下,seajs v1.2 会增加 mock 和 modify 功能。其中 modify 功能可用来快速修复线上 bug:

seajs/seajs#194

from aralejs.github.io.

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.