-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #6 -- Immutable records as datastructure for messages and pack…
…ages
- Loading branch information
Showing
8 changed files
with
131 additions
and
89 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
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
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
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
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
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 |
---|---|---|
@@ -1,4 +1,54 @@ | ||
/** | ||
* @module records | ||
* | ||
* Contains records used throughout the application. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var immutable = require('immutable'); | ||
const immutable = require('immutable'); | ||
|
||
|
||
class Message extends immutable.Record({ hasError: false, data: {} }) { | ||
constructor(data) { | ||
data.data = immutable.fromJS(data.data, function (key, value) { | ||
var isIndexed = immutable.Iterable.isIndexed(value); | ||
return isIndexed ? value.toList() : value.toOrderedMap(); | ||
}); | ||
|
||
super(data); | ||
} | ||
} | ||
|
||
const SuccessMsg = (data) => new Message({ | ||
data: data | ||
}); | ||
|
||
const ErrorMsg = (err) => new Message({ | ||
hasError: true, | ||
data: { | ||
err: err | ||
} | ||
}); | ||
|
||
const pkgDefaults = { | ||
isHost: true, | ||
basename: null, | ||
name: null, | ||
version: null, // only for host for semver check | ||
path: null, | ||
pjson: {}, | ||
isActivated: false, // Only for sub | ||
data: {} //only for sub host dep | ||
}; | ||
|
||
const Package = immutable.Record(pkgDefaults); | ||
const HostGenPkg = (pkg={}) => Package(Object.assign({}, pkgDefaults, pkg, { isHost: true })); | ||
const SubGenPkg = (pkg={}) => Package(Object.assign({}, pkgDefaults, pkg, { isHost: false })); | ||
|
||
module.exports = { | ||
SuccessMsg, | ||
ErrorMsg, | ||
HostGenPkg, | ||
SubGenPkg | ||
}; |
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
Oops, something went wrong.