Skip to content
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

Merged
merged 8 commits into from
Nov 30, 2024

Conversation

ishiko732
Copy link
Collaborator

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:
9c106da5fc5ba792bb776386f4b9409

Strategy pattern:
image

Copy link

codecov bot commented Nov 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (4663f21) to head (e703177).
Report is 3 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

@ishiko732 ishiko732 linked an issue Nov 24, 2024 that may be closed by this pull request
@joshdavham
Copy link
Member

@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.

@asukaminato0721
Copy link
Contributor

js has Proxy to be used with Reflect.
Or, what is the ideal API design?

@ishiko732
Copy link
Collaborator Author

js has Proxy to be used with Reflect. Or, what is the ideal API design?

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 xxx is not a function

@asukaminato0721
Copy link
Contributor

emm, assume the library is finished, how will the api look like?

@ishiko732
Copy link
Collaborator Author

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);

@ishiko732 ishiko732 merged commit 2845647 into main Nov 30, 2024
5 checks passed
@ishiko732 ishiko732 deleted the Feat/fsrs-plugin branch November 30, 2024 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Question] why the seed includes review_time.getTime()?
3 participants