-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from ncthbrt/feature/snapshotting
Feature/snapshotting
- Loading branch information
Showing
14 changed files
with
378 additions
and
72 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,43 +1,72 @@ | ||
class AfterValue { | ||
constructor (value) { | ||
Object.assign(this, value); | ||
} | ||
|
||
or (amount) { | ||
const { or, and, ...value } = this; | ||
return new After(amount, value, false); | ||
} | ||
|
||
and (amount) { | ||
const { or, and, ...value } = this; | ||
return new After(amount, value, true); | ||
} | ||
} | ||
|
||
class After { | ||
constructor (amount) { | ||
constructor (amount, chain = {}, addPreviousDuration) { | ||
this._amount = amount; | ||
this._chain = chain; | ||
this._previousDuration = (addPreviousDuration && this._chain.duration) ? this._chain.duration : 0; | ||
Object.freeze(this); | ||
} | ||
|
||
get hours () { | ||
return { duration: (this._amount * 60 * 60 * 1000) | 0 }; | ||
return new AfterValue({ ...this._chain, duration: (this._amount * 60 * 60 * 1000 + this._previousDuration) | 0 }); | ||
} | ||
|
||
get hour () { | ||
return this.hours; | ||
} | ||
|
||
get minutes () { | ||
return { duration: (this._amount * 60 * 1000) | 0 }; | ||
return new AfterValue({ ...this._chain, duration: (this._amount * 60 * 1000 + this._previousDuration) | 0 }); | ||
} | ||
|
||
get minute () { | ||
return this.minutes; | ||
} | ||
|
||
get seconds () { | ||
return { duration: (this._amount * 1000) | 0 }; | ||
return new AfterValue({ ...this._chain, duration: (this._amount * 1000 + this._previousDuration) | 0 }); | ||
} | ||
|
||
get second () { | ||
return this.seconds; | ||
} | ||
|
||
get milliseconds () { | ||
return { duration: this._amount | 0 }; | ||
return new AfterValue({ ...this._chain, duration: (this._amount + this._previousDuration) | 0 }); | ||
} | ||
|
||
get millisecond () { | ||
return this.milliseconds; | ||
} | ||
|
||
get messages () { | ||
return new AfterValue({ ...this._chain, messageInterval: this._amount }); | ||
} | ||
|
||
get message () { | ||
return this.messages; | ||
} | ||
} | ||
|
||
const after = (amount) => new After(amount); | ||
const every = (amount) => new After(amount); | ||
|
||
module.exports = { | ||
after | ||
after, | ||
every | ||
}; |
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
Oops, something went wrong.