Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
0b3c77c7
Commit
0b3c77c7
authored
May 21, 2022
by
boojack
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: remove customize redux
parent
8e01eb87
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
1 addition
and
160 deletions
+1
-160
consts.ts
web/src/helpers/consts.ts
+1
-1
Provider.tsx
web/src/labs/Provider.tsx
+0
-31
combineReducers.ts
web/src/labs/combineReducers.ts
+0
-36
createStore.ts
web/src/labs/createStore.ts
+0
-63
useSelector.ts
web/src/labs/useSelector.ts
+0
-29
No files found.
web/src/helpers/consts.ts
View file @
0b3c77c7
...
...
@@ -11,7 +11,7 @@ export const TOAST_ANIMATION_DURATION = 400;
export
const
DAILY_TIMESTAMP
=
3600
*
24
*
1000
;
// tag regex
export
const
TAG_REG
=
/#
\s?
(
.+
?)\s
/g
;
export
const
TAG_REG
=
/#
(
.+
?)\s
/g
;
// URL regex
export
const
LINK_REG
=
/
(
https
?
:
\/\/[^\s
<
\\
*>'
]
+
)
/g
;
...
...
web/src/labs/Provider.tsx
deleted
100644 → 0
View file @
8e01eb87
import
{
useEffect
,
useState
}
from
"react"
;
import
{
Store
}
from
"./createStore"
;
interface
Props
{
children
:
React
.
ReactElement
;
store
:
Store
<
any
,
any
>
;
context
:
React
.
Context
<
any
>
;
}
/**
* Toy-Redux Provider
* Just for debug with the app store
*/
const
Provider
:
React
.
FC
<
Props
>
=
(
props
:
Props
)
=>
{
const
{
children
,
store
,
context
:
Context
}
=
props
;
const
[
appState
,
setAppState
]
=
useState
(
store
.
getState
());
useEffect
(()
=>
{
const
unsubscribe
=
store
.
subscribe
((
ns
)
=>
{
setAppState
(
ns
);
});
return
()
=>
{
unsubscribe
();
};
},
[]);
return
<
Context
.
Provider
value=
{
appState
}
>
{
children
}
</
Context
.
Provider
>;
};
export
default
Provider
;
web/src/labs/combineReducers.ts
deleted
100644 → 0
View file @
8e01eb87
import
{
Action
,
Reducer
,
State
}
from
"./createStore"
;
interface
ReducersMapObject
<
S
extends
State
=
any
,
A
extends
Action
=
any
>
{
[
key
:
string
]:
Reducer
<
S
,
A
>
;
}
type
StateFromReducersMapObject
<
M
>
=
M
extends
ReducersMapObject
?
{
[
P
in
keyof
M
]:
M
[
P
]
extends
Reducer
<
infer
S
,
any
>
?
S
:
never
}
:
never
;
function
combineReducers
<
S
extends
State
,
A
extends
Action
>
(
reducers
:
ReducersMapObject
):
Reducer
<
S
,
A
>
{
const
reducerKeys
=
Object
.
keys
(
reducers
);
const
finalReducersObj
:
ReducersMapObject
=
{};
for
(
const
key
of
reducerKeys
)
{
if
(
typeof
reducers
[
key
]
===
"function"
)
{
finalReducersObj
[
key
]
=
reducers
[
key
];
}
}
return
((
state
:
StateFromReducersMapObject
<
typeof
reducers
>
=
{},
action
:
A
)
=>
{
let
hasChanged
=
false
;
const
nextState
:
StateFromReducersMapObject
<
typeof
reducers
>
=
{};
for
(
const
key
of
reducerKeys
)
{
const
prevStateForKey
=
state
[
key
];
const
nextStateForKey
=
finalReducersObj
[
key
](
prevStateForKey
,
action
);
nextState
[
key
]
=
nextStateForKey
;
hasChanged
=
hasChanged
||
nextStateForKey
!==
prevStateForKey
;
}
return
hasChanged
?
nextState
:
state
;
})
as
any
as
Reducer
<
S
,
A
>
;
}
export
default
combineReducers
;
web/src/labs/createStore.ts
deleted
100644 → 0
View file @
8e01eb87
export
type
State
=
Readonly
<
Record
<
string
,
any
>>
;
export
type
Action
=
{
type
:
string
;
payload
:
any
;
};
export
type
Reducer
<
S
extends
State
,
A
extends
Action
>
=
(
s
:
S
,
a
:
A
)
=>
S
;
type
Listener
<
S
extends
State
>
=
(
ns
:
S
,
ps
?:
S
)
=>
void
;
type
Unsubscribe
=
()
=>
void
;
export
interface
Store
<
S
extends
State
,
A
extends
Action
>
{
dispatch
:
(
a
:
A
)
=>
void
;
getState
:
()
=>
S
;
subscribe
:
(
listener
:
Listener
<
S
>
)
=>
Unsubscribe
;
}
/**
* Toy-Redux
* @param preloadedState initial state
* @param reducer reducer pure function
* @returns store
*/
function
createStore
<
S
extends
State
,
A
extends
Action
>
(
preloadedState
:
S
,
reducer
:
Reducer
<
S
,
A
>
):
Store
<
Readonly
<
S
>
,
A
>
{
const
listeners
:
Listener
<
S
>
[]
=
[];
let
currentState
=
preloadedState
;
const
dispatch
=
(
action
:
A
)
=>
{
const
nextState
=
reducer
(
currentState
,
action
);
const
prevState
=
currentState
;
currentState
=
nextState
;
for
(
const
cb
of
listeners
)
{
cb
(
currentState
,
prevState
);
}
};
const
subscribe
=
(
listener
:
Listener
<
S
>
)
=>
{
let
isSubscribed
=
true
;
listeners
.
push
(
listener
);
return
()
=>
{
if
(
!
isSubscribed
)
{
return
;
}
const
index
=
listeners
.
indexOf
(
listener
);
listeners
.
splice
(
index
,
1
);
isSubscribed
=
false
;
};
};
const
getState
=
()
=>
{
return
currentState
;
};
return
{
dispatch
,
getState
,
subscribe
,
};
}
export
default
createStore
;
web/src/labs/useSelector.ts
deleted
100644 → 0
View file @
8e01eb87
import
{
useEffect
,
useState
}
from
"react"
;
type
State
=
Readonly
<
Record
<
string
,
any
>>
;
interface
Action
{
type
:
string
;
}
type
Listener
<
S
extends
State
>
=
(
ns
:
S
,
ps
?:
S
)
=>
void
;
interface
Store
<
S
extends
State
,
A
extends
Action
>
{
dispatch
:
(
a
:
A
)
=>
void
;
getState
:
()
=>
S
;
subscribe
:
(
listener
:
Listener
<
S
>
)
=>
()
=>
void
;
}
export
default
function
useSelector
<
S
extends
State
,
A
extends
Action
>
(
store
:
Store
<
S
,
A
>
):
S
{
const
[
state
,
setState
]
=
useState
(
store
.
getState
());
useEffect
(()
=>
{
const
unsubscribe
=
store
.
subscribe
((
ns
)
=>
{
setState
(
ns
);
});
return
()
=>
{
unsubscribe
();
};
},
[]);
return
state
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment