-
-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/Impl initSeed
& Scheduler
extension based on the strategy pattern
#137
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #137 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 12 15 +3
Lines 652 684 +32
Branches 70 76 +6
=========================================
+ Hits 652 684 +32 ☔ View full report in Codecov by Sentry. |
@ishiko732 Hey man. I really wish I could help here, but I'm not familiar with either the Proxy or Stategy patterns so I don't really have an opinion on which would be preferrable here. |
js has Proxy to be used with |
The ideal API design is such that developers don’t have to write excessive logic to implement functionality. Using proxy requires developers to understand trap methods like get and apply, and if the proxy passed in by developers is not suitable, it could lead to errors like |
emm, assume the library is finished, how will the api look like? |
I hope the invocation would be like this: Proxy pattern import {createEmptyCard, fsrs, Rating, Grades, Card} from 'ts-fsrs';
function ProxyHandler(this: AbstractScheduler) {
return {
apply: function (this: AbstractScheduler) {
const card_id = Reflect.get(this, 'card_id') ?? 0
const reps = Reflect.get(this, 'reps') ?? 0
return String(card_id + reps || 0)
}.bind(this),
}
}
const f = fsrs().useProxy(ProxyMode.SEED, ProxyHandler);
// or const f= fsrs(params, proxies)
const now = new Date()
const card = createEmptyCard(now, (card: Card) => {
Object.assign(card, { card_id: 1234 })
return card
})
f.repeat(card, now); Strategy pattern import {createEmptyCard, fsrs, Rating, Grades, Card} from 'ts-fsrs';
function StrategyHandler(this: AbstractScheduler): string {
const card_id = Reflect.get(this.current, card_id_field) ?? 0
const reps = this.current.reps
return String(card_id + reps || 0)
}
const f = fsrs().useStrategy(StrategyMode.SEED, StrategyHandler);
// or const f= fsrs(params, strategies)
const now = new Date()
const card = createEmptyCard(now, (card: Card) => {
Object.assign(card, { card_id: 1234 })
return card
})
f.repeat(card, now); |
I attempted to implement these #131 features using the proxy pattern but found it difficult for developers to integrate, so I opted for a similar design pattern instead. Does anyone have other suggestions or better ideas?
Proxy pattern:
Strategy pattern: