1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 01:36:22 +00:00

using Repository class

This commit is contained in:
Rokt33r
2016-05-03 15:37:14 +09:00
parent 1d2ca469fc
commit 45c627b0a5
8 changed files with 151 additions and 747 deletions

View File

@@ -1,5 +1,59 @@
import reducer from './reducer'
import { createStore } from 'redux'
import { combineReducers, createStore } from 'redux'
import _ from 'lodash'
/**
* Repositories
* ```
* repositories = [{
* key: String,
* name: String,
* path: String, // path of repository
* status: String, // status of repository [IDLE, LOADING, READY, ERROR]
* folders: {
* name: String,
* color: String
* },
* notes: [{
* key: String,
* title: String,
* content: String,
* folder: String,
* tags: [String],
* createdAt: Date,
* updatedAt: Date
* }]
* }]
* ```
*/
const initialRepositories = []
function repositories (state = initialRepositories, action) {
console.log(action)
switch (action.type) {
case 'INIT_ALL':
return action.data.slice()
case 'ADD_REPOSITORY':
{
let repos = state.slice()
repos.push(action.repository)
return repos
}
case 'REMOVE_REPOSITORY':
{
let repos = state.slice()
let targetIndex = _.findIndex(repos, {key: action.key})
if (targetIndex > -1) {
repos.splice(targetIndex, 1)
}
return repos
}
}
return state
}
let reducer = combineReducers({
repositories
})
let store = createStore(reducer)