Last active
October 21, 2021 13:02
-
-
Save tomenden/e456e27b9a8d65c12482e8c0b9e80357 to your computer and use it in GitHub Desktop.
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
import {makeAutoObservable, autorun} from 'mobx' | |
import * as uuid from 'uuid' | |
class RepeaterStore { | |
constructor(){ | |
this.items = [] | |
} | |
} | |
function connectRepeater({selector = '#repeater1', initialData, renderItem}) { | |
const store = makeAutoObservable(new RepeaterStore()) | |
store.items = initialData.map(i => ({...i, _id: uuid.v4()})) | |
$w(selector).onItemReady((item, itemData) => { | |
autorun(() => renderItem(item, store.items.find((item) => item._id === itemData._id))) | |
}) | |
autorun(() => { | |
$w(selector).data = store.items.slice()} | |
) | |
return { | |
setData() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment