Skip to content

Instantly share code, notes, and snippets.

@Exodia
Last active August 29, 2015 14:17
Show Gist options
  • Save Exodia/d92f5129a8d0db6955bb to your computer and use it in GitHub Desktop.
Save Exodia/d92f5129a8d0db6955bb to your computer and use it in GitHub Desktop.
ioc interceptor
ioc.addInterceptor(
{
// add 方法会在注册组件前(addComponent)调用,
// 会传入 ioc 实例以及当前要注册的组件配置,
// 在此方法中可以自由的修改配置或者创建一个新的配置,最终必须得返回一个配置对象给 ioc,
// ioc 会用返回的配置对象作为当前正在注册的组件配置。
add: function(ioc, config) {
if(config.$dom) {
config.$dom = document.getElementById(config.$dom);
}
return config;
},
// get方法会在获取组件前(getComponent)调用,
// 会传入 ioc 实例,当前的组件配置,创建好的实例,
// 在此方法中,可以对根据配置对实例进行自由的修改,不推荐在此修改配置。
// 最终的返回值会作为组件实例传给 getComponent 的 callback;
get: function (ioc, config, instance) {
if(config.$guid) {
instance.guid = config.$guid();
}
return instance;
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment