Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/dobPublic

Commitf67d4c5

Browse files
committed
feat: use strict mode
1 parent03c3d78 commitf67d4c5

File tree

11 files changed

+52
-49
lines changed

11 files changed

+52
-49
lines changed

‎demos/action/index.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ const stores = combineStores({
3636
})
3737

3838
observe(()=>{
39-
console.log("observe",stores.Store1.age,stores.Store2.name)
39+
// tslint:disable-next-line:no-console
40+
console.log("observe",stores!.Store1!.age,stores!.Store2!.name)
4041
})
4142

42-
stores.Action2.test2()
43+
stores!.Action2!.test2()

‎demos/debug/index.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ const stores = combineStores({
4343
Action2
4444
})
4545

46-
stores.Action2.test2()
46+
stores!.Action2!.test2()

‎package.json‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name":"dob",
3-
"version":"2.5.4",
3+
"version":"2.5.5",
44
"description":"",
55
"main":"built/src/index.js",
66
"types":"src/index.ts",
@@ -51,7 +51,7 @@
5151
"webpack":"^3.3.0"
5252
},
5353
"dependencies": {
54-
"dependency-inject":"^1.1.1",
54+
"dependency-inject":"^1.1.3",
5555
"lodash.clonedeep":"^4.5.0"
5656
},
5757
"pre-commit": [
@@ -75,4 +75,4 @@
7575
"react-dom"
7676
]
7777
}
78-
}
78+
}

‎src/debug.ts‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const cloneDeep = require("lodash.clonedeep")
77

88
functionreportChange(change:IDebugChange){
99
if(globalState.currentDebugOutputAction){
10-
globalState.currentDebugOutputAction.changeList.push(change)
10+
globalState!.currentDebugOutputAction!.changeList!.push(change)
1111
}else{// Changes out of Action.
1212
globalState.event.emit("debug",{
1313
id:createUniqueId(),
@@ -31,14 +31,14 @@ function getCallStack(target: object) {
3131
constparentInfo=globalState.parentInfo.get(currentTarget)
3232

3333
// add key to call stack
34-
callStack.unshift(parentInfo.key)
34+
callStack.unshift(parentInfo!.key)
3535

3636
// If has no parent's parent, add parent's name to call stack.
37-
if(!globalState.parentInfo.has(parentInfo.parent)){
38-
callStack.unshift(parentInfo.parent.constructor.name)
37+
if(!globalState.parentInfo.has(parentInfo!.parent)){
38+
callStack.unshift(parentInfo!.parent.constructor.name)
3939
}
4040

41-
currentTarget=parentInfo.parent
41+
currentTarget=parentInfo!.parent
4242

4343
runCount++
4444
if(runCount>=globalState.getCallstackMaxCount){
@@ -58,10 +58,10 @@ globalState.event.on("get", info => {
5858
return
5959
}
6060

61-
if(info.value!==null&&typeofinfo.value==="object"){
62-
globalState.parentInfo.set(info.value,{
63-
parent:info.target,
64-
key:info.key
61+
if(info!.value!==null&&typeofinfo!.value==="object"){
62+
globalState.parentInfo.set(info!.value,{
63+
parent:info!.target,
64+
key:info!.key
6565
})
6666
}
6767
})
@@ -102,7 +102,7 @@ globalState.event.on("startBatch", () => {
102102

103103
// 如果当前深度大于 1,就作为加到父级的 changeList
104104
if(globalState.batchDeep>1){
105-
globalState.debugOutputActionMapBatchDeep.get(globalState.batchDeep-1).changeList.push({
105+
globalState!.debugOutputActionMapBatchDeep!.get(globalState.batchDeep-1)!.changeList!.push({
106106
type:"action",
107107
action:debugOutputBundleAction
108108
})
@@ -118,10 +118,10 @@ globalState.event.on("endBatch", () => {
118118
}
119119

120120
// 每次出栈,都要更新 currentDebugOutputAction
121-
globalState.currentDebugOutputAction=globalState.debugOutputActionMapBatchDeep.get(globalState.batchDeep)
121+
globalState.currentDebugOutputAction=globalState.debugOutputActionMapBatchDeep.get(globalState.batchDeep)||null
122122

123123
if(!inAction()){
124-
letcloneDebugInfo:IDebugInfo=null
124+
letcloneDebugInfo:IDebugInfo|null=null
125125

126126
try{
127127
cloneDebugInfo=JSON.parse(JSON.stringify(globalState.debugOutputActionMapBatchDeep.get(1)))
@@ -146,14 +146,14 @@ globalState.event.on("set", info => {
146146
return
147147
}
148148

149-
constcallStack=getCallStack(info.target)
149+
constcallStack=getCallStack(info!.target)
150150

151151
reportChange({
152152
type:"change",
153153
callStack,
154-
oldValue:cloneDeep(info.oldValue),
155-
key:info.key,
156-
value:cloneDeep(info.value)
154+
oldValue:cloneDeep(info!.oldValue),
155+
key:info!.key,
156+
value:cloneDeep(info!.value)
157157
})
158158
})
159159

@@ -165,11 +165,11 @@ globalState.event.on("deleteProperty", info => {
165165
return
166166
}
167167

168-
constcallStack=getCallStack(info.target)
168+
constcallStack=getCallStack(info!.target)
169169

170170
reportChange({
171171
type:"delete",
172172
callStack,
173-
key:info.key,
173+
key:info!.key,
174174
})
175175
})

‎src/event/index.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class Event {
4242

4343
if(this.events.get(eventType)){
4444
// 存在, push 一个事件监听
45-
this.events.get(eventType).push(event)
45+
this!.events!.get(eventType)!.push(event)
4646
}else{
4747
// 不存在, 赋值
4848
this.events.set(eventType,[event])
@@ -57,7 +57,7 @@ export class Event {
5757
returnfalse
5858
}
5959

60-
constevents=this.events.get(eventType).filter(event=>{
60+
constevents=this!.events!.get(eventType)!.filter(event=>{
6161
returnevent.callback!==callback
6262
})
6363

@@ -74,7 +74,7 @@ export class Event {
7474
returnfalse
7575
}
7676

77-
this.events.get(eventType).forEach(event=>{
77+
this!.events!.get(eventType)!.forEach(event=>{
7878
event.callback(context)
7979
})
8080
}

‎src/global-state.ts‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import { Func } from "./utils"
44

55
consttag="ascoders-dob"
66

7-
constglobalOrWindow=(typeofself==="object"&&self.self===self&&self)||
8-
(typeofglobal==="object"&&global.global===global&&global)||
9-
this
7+
constglobalOrWindow:any=(typeofself==="object"&&self.self===self&&self)||
8+
(typeofglobal==="object"&&global.global===global&&global)
109

1110
exportinterfaceIDebugInfo{
1211
/**
@@ -16,7 +15,7 @@ export interface IDebugInfo {
1615
/**
1716
* The name of Action.
1817
*/
19-
name?:string
18+
name?:string|null
2019
/**
2120
* Changes
2221
*/
@@ -60,7 +59,7 @@ class GlobalState {
6059
* Store all the original objects and keys to be proxied.
6160
*/
6261
publicobjectReactionBindings=newWeakMap<object,Map<PropertyKey,Set<Reaction>>>()
63-
publiccurrentReaction:Reaction=null
62+
publiccurrentReaction:Reaction|null=null
6463
/**
6564
* Batch execution depth, such as each call runInAction in-depth +1, call -1, depth of 0 means that the implementation of the end.
6665
* When batchDeep == = 0, the operation queue is completed.
@@ -85,7 +84,7 @@ class GlobalState {
8584
/**
8685
* The currently executing debugOutputAction object.
8786
*/
88-
publiccurrentDebugOutputAction:IDebugInfo=null
87+
publiccurrentDebugOutputAction:IDebugInfo|null=null
8988
/**
9089
* The root of each batchDeep debugOutputBundleAction.
9190
*/
@@ -100,8 +99,8 @@ class GlobalState {
10099
/**
101100
* Special for action name.
102101
*/
103-
publiccurrentDebugName:string=null
104-
publiccurrentDebugId:number=null
102+
publiccurrentDebugName:string|null=null
103+
publiccurrentDebugId:number|null=null
105104
publicstrictMode=false
106105
publicevent=newEvent()
107106
publicuniqueIdCounter=0

‎src/observer.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,9 @@ function Action(fn: () => any | Promise<any>): void
268268
functionAction(target:any,propertyKey:string,descriptor:PropertyDescriptor):any
269269
functionAction(arg1:any,arg2?:any,arg3?:any){
270270
if(arg2===undefined){
271-
returnrunInAction.call(this,arg1,arg1.name)
271+
returnrunInAction.call(null,arg1,arg1.name)
272272
}
273-
returnactionDecorator.call(this,arg1,arg1.constructor.name+"."+arg2,arg3)
273+
returnactionDecorator.call(null,arg1,arg1.constructor.name+"."+arg2,arg3)
274274
}
275275

276276
functionactionDecorator(target:any,propertyKey:string,descriptor:PropertyDescriptor){

‎src/reaction.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,30 @@ export class Reaction {
77
privatename:string
88

99
// Run reaction's delay.
10-
privatedelay:number=null
10+
privatedelay:number|null=null
1111

1212
// Binders for this reaction.
1313
// Binder include callback, and it's detail info, like delay.
1414
privatekeyBinders=newSet<IKeyBinder>()
1515

1616
// Callback for this reaction.
17-
privatecallback:IFunc
17+
privatecallback:IFunc|null
1818

1919
constructor(name:string,callback:IFunc,delay?:number){
2020
this.name=name
2121
this.callback=callback
22-
this.delay=delay
22+
this.delay=delay||null
2323
}
2424

2525
/**
2626
* The variables accessed in track are bound to the current reaction, which triggers binder's callback when the variables are modified.
2727
*@TODO: Current only support synchronization, do not support asynchronous!
2828
*/
2929
publictrack(callback?:IFunc){
30+
if(!callback){
31+
return
32+
}
33+
3034
// If it is already in track, add this directly to the pendingTrack queue, and return.
3135
// When the lastest runObserver is executed, current pendingTrack will executed.
3236
if(inTrack()){

‎tests/debug.test.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ test("test callstack", async t => {
106106
return
107107
}
108108
once=false
109-
callStack=debugInfo.changeList[0].callStack
109+
callStack=debugInfo!.changeList![0].callStack||[]
110110
})
111111

112112
store.a.b.c.d.e.f="d"
@@ -147,7 +147,7 @@ test("test overflow callstack", async t => {
147147
return
148148
}
149149
once=false
150-
callStack=debugInfo.changeList[0].callStack
150+
callStack=debugInfo!.changeList![0].callStack||[]
151151
})
152152

153153
store.a.b.c.d.e.f="d"
@@ -185,7 +185,7 @@ test("test action", async t => {
185185
}
186186
once=false
187187

188-
deletedebugInfo.id
188+
deletedebugInfo!.id
189189
t.deepEqual(debugInfo,{
190190
name:"CustomAction.action1",
191191
changeList:[
@@ -232,8 +232,8 @@ test("test delete", async t => {
232232
}
233233
once=false
234234

235-
deletedebugInfo.id
236-
t.deepEqual(debugInfo,{
235+
deletedebugInfo!.id
236+
t.deepEqual(debugInfo||{},{
237237
name:null,
238238
changeList:[
239239
{

‎tests/observer.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,11 +691,11 @@ test("should observe map array", t => {
691691
constdynamicObj=observable(newMap<string,number[]>([
692692
["a",[1,2,3]]
693693
]))
694-
observe(()=>data=dynamicObj.get("a").length)
694+
observe(()=>data=dynamicObj!.get("a")!.length)
695695

696696
returnPromise.resolve()
697697
.then(()=>t.true(data===3))
698-
.then(()=>dynamicObj.get("a").push(4))
698+
.then(()=>dynamicObj!.get("a")!.push(4))
699699
.then(()=>t.true(data===4))
700700
})
701701

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp