LearnNewsExamplesServices
Frontmatter
id2368
titlemodel.Component: support for twoWay bindings
stateClosed
labels
enhancement
assigneestobiu
createdAtJun 15, 2021, 11:28 AM
updatedAtJun 15, 2021, 11:29 AM
githubUrlhttps://github.com/neomjs/neo/issues/2368
authortobiu
commentsCount0
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtJun 15, 2021, 11:29 AM

model.Component: support for twoWay bindings

Closed v8.1.0 enhancement
tobiu
tobiu commented on Jun 15, 2021, 11:28 AM

A one way binding looks like this:

bind: {
    startTime: value: data => data.startTime
}

It should be optionally possible to not only update component configs when view model data props change, but also support the other direction. Change a component configs => update the bound model data property.

bind: {
    startTime: {twoWay: true, value: data => data.startTime}
}

To do this, model.Component needs to check if a config object was passed. If so, use value.value.

Neo.mjs: set() needs an update, to also call this.afterSetConfig() in case the fn does exist.

This method needs to get implemented on component.Base (lowest VM entry point).

afterSetConfig(key, value, oldValue) {
    if (Neo.currentWorker.isUsingViewModels) {
        let me   = this,
            bind = me.bind;

        if (bind && bind[key] && bind[key].twoWay) {
            me.getModel().setData(key, value);
        }
    }
}
tobiu added the enhancement label on Jun 15, 2021, 11:28 AM
tobiu assigned to @tobiu on Jun 15, 2021, 11:28 AM
tobiu referenced in commit 7c4c7ff - "model.Component: support for twoWay bindings #2368" on Jun 15, 2021, 11:29 AM
tobiu closed this issue on Jun 15, 2021, 11:29 AM