-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 80f9a92
Showing
40 changed files
with
11,152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# TypeScript v1 declaration files | ||
typings/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Microbundle cache | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
.env.test | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
.parcel-cache/ | ||
|
||
# Next.js build output | ||
.next | ||
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
.cache/ | ||
# Comment in the public line in if your project uses Gatsby and *not* Next.js | ||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
# public | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
# TernJS port file | ||
.tern-port | ||
|
||
# npm | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Xvezda <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# :eyes: vom.js | ||
React-like 인터페이스를 제공하는 SPA 프레임워크 | ||
|
||
## Demo | ||
|
||
https://xvezda.github.io/vom.js/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"version": "0.0.0", | ||
"npmClient": "yarn", | ||
"useWorkspaces": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "@vomjs/monorepo", | ||
"author": { | ||
"name": "Xvezda", | ||
"email": "[email protected]", | ||
"url": "https://xvezda.com/" | ||
}, | ||
"scripts": { | ||
"bootstrap": "lerna bootstrap", | ||
"build": "yarn workspace vomjs build" | ||
}, | ||
"devDependencies": { | ||
"gh-pages": "^3.2.3", | ||
"lerna": "^4.0.0" | ||
}, | ||
"workspaces": [ | ||
"packages/*", | ||
"packages/**/examples/*" | ||
], | ||
"private": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# @vomjs/store | ||
|
||
[Flux](https://facebook.github.io/flux/), [Redux](https://redux.js.org/)의 인터페이스를 참고하여 구현한 상태관리 모듈입니다. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "@vomjs/store", | ||
"version": "0.0.0", | ||
"description": "Flux 아키텍처를 구현한 상태관리 모듈", | ||
"main": "src/index.js", | ||
"devDependencies": { | ||
"@babel/core": "^7.15.5", | ||
"babel-jest": "^27.2.0", | ||
"jest": "^27.2.0" | ||
}, | ||
"scripts": { | ||
"test": "jest" | ||
}, | ||
"author": { | ||
"name": "Xvezda", | ||
"email": "[email protected]", | ||
"url": "https://xvezda.com/" | ||
}, | ||
"keywords": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
export default class Dispatcher { | ||
constructor() { | ||
this.$callbacks = new Map; | ||
this.$pending = new Set; | ||
this.$id = -1; | ||
this._invokeId = -1; | ||
this._pendingPayload = undefined; | ||
|
||
this._invokeCallback = this._invokeCallback.bind(this); | ||
this._broadcast = this._broadcast.bind(this); | ||
this.waitFor = this.waitFor.bind(this); | ||
this.register = this.register.bind(this); | ||
this.unregister = this.unregister.bind(this); | ||
this.dispatch = this.dispatch.bind(this); | ||
this.isDispatching = this.isDispatching.bind(this); | ||
} | ||
|
||
_invokeCallback(id) { | ||
this._invokeId = id; | ||
if (this.$pending.has(id)) { | ||
this.waitFor([...this.$pending]); | ||
} else { | ||
this.$pending.add(id); | ||
this.$callbacks.get(id)(this._pendingPayload); | ||
this.$pending.delete(id); | ||
} | ||
this._invokeId = -1; | ||
} | ||
|
||
_broadcast() { | ||
[...this.$callbacks.keys()].forEach(this._invokeCallback); | ||
} | ||
|
||
register(callback) { | ||
++this.$id; | ||
this.$callbacks.set(this.$id, callback); | ||
return this.$id; | ||
} | ||
|
||
unregister(id) { | ||
this.$callbacks.delete(id); | ||
} | ||
|
||
waitFor(ids) { | ||
this.$pending.add(this._invokeId); | ||
const copy = new Set([...ids]); | ||
while ([...copy].filter(id => typeof id !== 'undefined').map(id => this.$pending.has(id)).some(x => x)) { | ||
[...copy].forEach(id => { | ||
copy.delete(id); | ||
this.$pending.delete(id); | ||
this._invokeCallback(id); | ||
}); | ||
} | ||
} | ||
|
||
dispatch(payload) { | ||
if (!this.isDispatching()) { | ||
this._pendingPayload = payload; | ||
this._broadcast(); | ||
this._pendingPayload = undefined; | ||
} | ||
this.$pending.clear(); | ||
} | ||
|
||
isDispatching() { | ||
return this._invokeId !== -1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { default as Dispatcher } from './dispatcher.js'; | ||
export { default as Store } from './store.js'; | ||
export { ReduceStore, createStore } from './reduce.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import Dispatcher from './dispatcher.js'; | ||
import Store from './store.js'; | ||
|
||
export class ReduceStore extends Store { | ||
constructor(dispatcher) { | ||
super(dispatcher); | ||
this.$state = this.getInitialState(); | ||
} | ||
|
||
getState() { | ||
return this.$state; | ||
} | ||
|
||
getInitialState() {} | ||
|
||
/* eslint-disable-next-line no-unused-vars */ | ||
reduce(state, action) {} | ||
|
||
areEqual(one, two) { | ||
return Object.is(one, two); | ||
} | ||
|
||
onDispatch(payload) { | ||
const newState = this.reduce(this.getState(), payload); | ||
if (!this.areEqual(newState, this.getState())) { | ||
this.$state = newState; | ||
} | ||
} | ||
} | ||
|
||
export const createStore = (reducer) => { | ||
const dispatcher = new Dispatcher; | ||
class CreatedStore extends ReduceStore { | ||
dispatch(payload) { | ||
return dispatcher.dispatch(payload); | ||
} | ||
} | ||
CreatedStore.prototype.reduce = reducer; | ||
CreatedStore.prototype.subscribe = ReduceStore.prototype.addListener; | ||
|
||
const store = new CreatedStore(dispatcher); | ||
dispatcher.dispatch({type: '@@store/INIT'}); | ||
|
||
return store; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { jest } from '@jest/globals'; | ||
import { createStore } from './reduce.js'; | ||
|
||
test('카운터 예제 테스트', () => { | ||
// Redux-like 인터페이스를 테스트하기 위해 동일한 예제를 사용한다. | ||
// https://redux.js.org/introduction/getting-started | ||
function counterReducer(state = {value: 0}, action) { | ||
switch (action.type) { | ||
case 'counter/incremented': | ||
return {value: state.value + 1}; | ||
case 'counter/decremented': | ||
return {value: state.value - 1}; | ||
default: | ||
return state; | ||
} | ||
} | ||
|
||
const store = createStore(counterReducer); | ||
const subscriberMock = jest.fn(); | ||
store.subscribe(() => subscriberMock(store.getState())); | ||
|
||
store.dispatch({type: 'counter/incremented'}); | ||
expect(subscriberMock).toHaveBeenCalledWith({value: 1}); | ||
store.dispatch({type: 'counter/incremented'}); | ||
expect(subscriberMock).toHaveBeenCalledWith({value: 2}); | ||
store.dispatch({type: 'counter/decremented'}); | ||
expect(subscriberMock).toHaveBeenCalledWith({value: 1}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
export default class Store { | ||
constructor(dispatcher) { | ||
this.$id = -1; | ||
this.$dispatcher = dispatcher; | ||
this.$callbacks = new Map; | ||
this.$changed = false; | ||
|
||
dispatcher.register(payload => this.onDispatch(payload)); | ||
} | ||
|
||
addListener(callback) { | ||
this.$id = this.$dispatcher.register(callback); | ||
return { | ||
remove: this.$dispatcher.unregister.bind(this.$dispatcher, this.$id) | ||
}; | ||
} | ||
|
||
getDispatcher() { | ||
return this.$dispatcher; | ||
} | ||
|
||
getDispatchToken() { | ||
return this.$id; | ||
} | ||
|
||
hasChanged() { | ||
return this.$changed; | ||
} | ||
|
||
_emitChange() { | ||
this.$changed = true; | ||
} | ||
|
||
/* eslint-disable-next-line no-unused-vars */ | ||
onDispatch(payload) { | ||
throw new Error('subclasses must override onDispatch()'); | ||
} | ||
} |
Oops, something went wrong.