Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ajax加载的模板中调用seajs.use #13

Open
ckrad opened this issue Apr 22, 2015 · 4 comments
Open

ajax加载的模板中调用seajs.use #13

ckrad opened this issue Apr 22, 2015 · 4 comments

Comments

@ckrad
Copy link

ckrad commented Apr 22, 2015

我在ajax加载的模板中调用seajs.use 模块不会被加载。后来我发现需要再次调用seajs.flush() 我本来以为全站只需要底部调用一次seajs.flush() 后来发现这是不太可能的 不过我觉得这样的情况有必要在文档中说明一下

@army8735
Copy link
Member

呃……flush自然是flush之前的缓存,不可能之后的……

@ckrad
Copy link
Author

ckrad commented Apr 27, 2015

@army8735 我在全站底部flush了一遍 如果我后面再ajax进来的模板在里面调用seajs.use 执行的脚本应该是不会和别的脚本合并的 所以是不是可以在底部调用flush之后 再执行一个操作让seajs-flush失效 这样后面我加载进来的内容就没必要调一下seajs.flush 我用seajs-flush前面确实没有意识到需要多次flush 所以我觉得可以把这种问题给规避掉

@army8735
Copy link
Member

没这个特性……可以试试提个mr

@ckrad
Copy link
Author

ckrad commented Apr 30, 2015

var off = false


var flushOn = function() {
  Module.prototype.load = function() {
    var mod = this

    if (needLoadImmediately(mod)) {
      load.call(mod)
    }
    else {
      isInUse ? useStack.push(mod) : depStack.push(mod)
    }
  }

  seajs.use = function(ids, callback) {
    isInUse = true
    Module.use(ids, callback, data.cwd + "_use_" + data.cid())
    isInUse = false

    return seajs
  }

  off = false
}
flushOn()

var flushOff = function () {
  seajs.use = seajs.Module.use
  Module.prototype.load = load
  off = true
}

seajs.flush = function() {

  if (arguments[0] === "off") {
    if (!off) {
      flushOff()
    }
    return
  }

  if (off) {
    flushOn()
  }

  flush(useStack)
}

@army8735 我修改了这些代码 跑test/runner.html的时候 当我在spec下的test.html第71行加入seajs.flush('off')的时候测试不通过 但是我再seajs.flush('off')设置断点 运行的时候又是可以通过的 不明白为什么

我拿编译后的文件在自己的项目里测试过是达到了我自己要的目的 在网页底部我flush了之后 立即执行了flush('off') 我ajax进来的模板就不需要在执行一遍flush

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants