Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Sunny_yiyi
Swagger Ui
提交
9d48c475
S
Swagger Ui
项目概览
Sunny_yiyi
/
Swagger Ui
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Swagger Ui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
9d48c475
编写于
12月 28, 2017
作者:
K
Kyle Shockey
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor `afterLoad` interface to expose raw plugin context
上级
1646b270
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
118 addition
and
14 deletion
+118
-14
docs/customization/plugin-api.md
docs/customization/plugin-api.md
+7
-4
src/core/plugins/auth/index.js
src/core/plugins/auth/index.js
+2
-1
src/core/system.js
src/core/system.js
+24
-7
test/core/system/system.js
test/core/system/system.js
+85
-2
未找到文件。
docs/customization/plugin-api.md
浏览文件 @
9d48c475
...
...
@@ -19,7 +19,7 @@ A plugin return value may contain any of these keys, where `myStateKey` is a nam
},
components
:
{},
wrapComponents
:
{},
afterLoad
:
(
system
)
=>
{}
afterLoad
:
(
system
)
=>
{}
,
fn
:
{},
}
```
...
...
@@ -366,9 +366,11 @@ const MyWrapComponentPlugin = function(system) {
##### `afterLoad`
The
`afterLoad`
plugin method allows you to get a reference to the system after your plugin has been registered
with the system
.
The
`afterLoad`
plugin method allows you to get a reference to the system after your plugin has been registered.
This interface is used in the core code to attach methods that are driven by bound selectors or actions directly to the system.
This interface is used in the core code to attach methods that are driven by bound selectors or actions directly to the plugin context.
The plugin context, which is bound to
`this`
, is undocumented, but below is an example of how to attach a bound action as a top-level method:
```
javascript
const
MyMethodProvidingPlugin
=
function
()
{
...
...
@@ -376,7 +378,8 @@ const MyMethodProvidingPlugin = function() {
afterLoad
(
system
)
{
// at this point in time, your actions have been bound into the system
// so you can do things with them
system
.
myMethod
=
system
.
exampleActions
.
updateFavoriteColor
this
.
rootInjects
=
this
.
rootInjects
||
{}
this
.
rootInjects
.
myMethod
=
system
.
exampleActions
.
updateFavoriteColor
},
statePlugins
:
{
example
:
{
...
...
src/core/plugins/auth/index.js
浏览文件 @
9d48c475
...
...
@@ -6,7 +6,8 @@ import * as specWrapActionReplacements from "./spec-wrap-actions"
export
default
function
()
{
return
{
afterLoad
(
system
)
{
system
.
initOAuth
=
system
.
authActions
.
configureAuth
this
.
rootInjects
=
this
.
rootInjects
||
{}
this
.
rootInjects
.
initOAuth
=
system
.
authActions
.
configureAuth
},
statePlugins
:
{
auth
:
{
...
...
src/core/system.js
浏览文件 @
9d48c475
...
...
@@ -68,13 +68,11 @@ export default class Store {
if
(
rebuild
)
{
this
.
buildSystem
()
}
if
(
Array
.
isArray
(
plugins
))
{
plugins
.
forEach
(
plugin
=>
{
if
(
plugin
.
afterLoad
)
{
plugin
.
afterLoad
(
this
.
getSystem
())
}
})
const
needAnotherRebuild
=
callAfterLoad
.
call
(
this
.
system
,
plugins
,
this
.
getSystem
())
if
(
needAnotherRebuild
)
{
this
.
buildSystem
()
}
}
...
...
@@ -328,6 +326,25 @@ function combinePlugins(plugins, toolbox) {
return
{}
}
function
callAfterLoad
(
plugins
,
system
,
{
hasLoaded
}
=
{})
{
let
calledSomething
=
hasLoaded
if
(
isObject
(
plugins
)
&&
!
isArray
(
plugins
))
{
if
(
typeof
plugins
.
afterLoad
===
"
function
"
)
{
calledSomething
=
true
plugins
.
afterLoad
.
call
(
this
,
system
)
}
}
if
(
isFunc
(
plugins
))
return
callAfterLoad
.
call
(
this
,
plugins
(
system
),
system
,
{
hasLoaded
:
calledSomething
})
if
(
isArray
(
plugins
))
{
return
plugins
.
map
(
plugin
=>
callAfterLoad
.
call
(
this
,
plugin
,
system
,
{
hasLoaded
:
calledSomething
}))
}
return
calledSomething
}
// Wraps deepExtend, to account for certain fields, being wrappers.
// Ie: we need to convert some fields into arrays, and append to them.
// Rather than overwrite
...
...
test/core/system/system.js
浏览文件 @
9d48c475
...
...
@@ -684,13 +684,13 @@ describe("bound system", function(){
})
describe
(
"
afterLoad
"
,
function
()
{
it
(
"
should call a
n
plugin's `afterLoad` method after the plugin is loaded
"
,
function
()
{
it
(
"
should call a plugin's `afterLoad` method after the plugin is loaded
"
,
function
()
{
// Given
const
system
=
new
System
({
plugins
:
[
{
afterLoad
(
system
)
{
system
.
wow
=
system
.
dogeSelectors
.
wow
this
.
rootInjects
.
wow
=
system
.
dogeSelectors
.
wow
},
statePlugins
:
{
doge
:
{
...
...
@@ -705,6 +705,89 @@ describe("bound system", function(){
]
})
// When
var
res
=
system
.
getSystem
().
wow
()
expect
(
res
).
toEqual
(
"
so selective
"
)
})
it
(
"
should call a preset plugin's `afterLoad` method after the plugin is loaded
"
,
function
()
{
// Given
const
MyPlugin
=
{
afterLoad
(
system
)
{
this
.
rootInjects
.
wow
=
system
.
dogeSelectors
.
wow
},
statePlugins
:
{
doge
:
{
selectors
:
{
wow
:
()
=>
(
system
)
=>
{
return
"
so selective
"
}
}
}
}
}
const
system
=
new
System
({
plugins
:
[
[
MyPlugin
]
]
})
// When
var
res
=
system
.
getSystem
().
wow
()
expect
(
res
).
toEqual
(
"
so selective
"
)
})
it
(
"
should call a function preset plugin's `afterLoad` method after the plugin is loaded
"
,
function
()
{
// Given
const
MyPlugin
=
{
afterLoad
(
system
)
{
this
.
rootInjects
.
wow
=
system
.
dogeSelectors
.
wow
},
statePlugins
:
{
doge
:
{
selectors
:
{
wow
:
()
=>
(
system
)
=>
{
return
"
so selective
"
}
}
}
}
}
const
system
=
new
System
({
plugins
:
[
()
=>
{
return
[
MyPlugin
]
}
]
})
// When
var
res
=
system
.
getSystem
().
wow
()
expect
(
res
).
toEqual
(
"
so selective
"
)
})
it
(
"
should call a registered plugin's `afterLoad` method after the plugin is loaded
"
,
function
()
{
// Given
const
MyPlugin
=
{
afterLoad
(
system
)
{
this
.
rootInjects
.
wow
=
system
.
dogeSelectors
.
wow
},
statePlugins
:
{
doge
:
{
selectors
:
{
wow
:
()
=>
(
system
)
=>
{
return
"
so selective
"
}
}
}
}
}
const
system
=
new
System
({
plugins
:
[]
})
system
.
register
([
MyPlugin
])
// When
var
res
=
system
.
getSystem
().
wow
()
expect
(
res
).
toEqual
(
"
so selective
"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录