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

Extend MemoryStore class with synced properties #7

Merged
merged 2 commits into from
Dec 25, 2016

Conversation

gazay
Copy link
Member

@gazay gazay commented Dec 16, 2016

@ai What do you think about API for synced/otherSynced like this? Please check if it is ok – I'll write tests

* getSynced, setSynced.
*
* @param {object} [options] Store options.
* @param {number} [options.synced=0] Events with lower `added` time in current
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you was confused about names first time, maybe we should change key names? current/other?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As they will be properties of store object – just current/other will be not enough. How about currentSynced/otherSynced?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. But current not looks so clear. Sync#currentProtocol looks like a protocol version of current connection. Also other prefix is not good too.

Maybe there are a special terms for it in other protocol docs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In couple swift libraries I found local/remote prefixes for this case. Also in scuttlebut (https://github.com/dominictarr/scuttlebutt/blob/master/index.js) they used latest + syncSent/syncRecv. I thinking about something like latestClient/latestServer or clientSynced/serverSynced as it will be used in client nodes – so we'll always know what is client and what is server in this case. Also yeah – can work localSynced/remoteSynced

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great overview. I like the idea of localProtocol/remoteProtocol!

But cleint* and server* prefix could not be used, because logux-sync could be used in server-server communication :(. But latestSent, latestReceived looks great! Maybe even better than localSynced/remoteSynced, because it is more clear.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setOptions and setExtra don't tell anything about synchronization state, looks too general, like if you want to set name of store or something. Maybe setLatestSync?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeap, setLatestSynced({ sent, received }) looks good.

But maybe having a general open-structure data is good too? What if some future Logux plugins will need to save some data to Store?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it can be useful (setOptions/setProperties/setData/setExtra) in future but as we don't have cases now – lets add this *LatestSynced methods and after we'll implement more database stores – we'll see what we could need and then change API. I think it will be clear before next version release and we'll change it to more general names later if we'll need it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, lets start with *LatestSynced

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated code and tests to *LatestSynced with argument and return value as parameter

this.created = []
this.added = []
this.options = options || {}
this.synced = this.options.synced || 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this options if we can’t set default events in MemorySrore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it is redundant here.

*/
getSynced: function getSynced () {
var store = this
return new Promise(function (resolve) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is Promise.resolve(value) shortcut for it. Same with setSynced.

@ai ai merged commit 12a0c01 into logux:master Dec 25, 2016
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.

2 participants