Knockout.js 和 ScriptSharp - 可写的依赖 Observables

发布于 2024-12-08 19:37:29 字数 226 浏览 0 评论 0原文

我正在使用并且非常享受 Knockout.js 和 Script# 的邪恶组合#

在探索依赖可观察量的强大功能时,我遇到了需要实现可写变体的需求,如 文档

您如何在 Script Sharp 导入类中捕获此 ko 函数?

I'm using and really enjoying a wicked combination of knockout.js and Script#

While exploring the power of Dependent Observables, i've come across a need to implement the Writable variation as referred to in the documentation

How would you capture this ko function in the Script Sharp import class?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

待天淡蓝洁白时 2024-12-15 19:37:29

我最终制作了一个新的“导入库”项目
并定义了缺失的部分。

namespace KnockoutApi
{
    [Imported]
    [IgnoreNamespace]
    [ScriptName("ko")]
    public static class Ko
    {
        /// <summary>
        /// Creates an observable with a value computed from one or more other values.
        /// </summary>
        /// <typeparam name="T">The type of the observable value.</typeparam>
        /// <param name="options">Options for the dependent observable.</param>
        public static DependentObservable<T> DependentObservable<T>(DependentObservableWritableOptions<T> options)
        {
            return null;
        }
    }
}


[IgnoreNamespace]
[Imported]
[ScriptName("Object")]
public class DependentObservableWritableOptions<T>
{
    public DependentObservableWritableOptions()
    { }

    // Summary:
    //     Gets or sets whether the evaluation should be deferred, i.e. not performed
    //     when the observable is first created.
    [IntrinsicProperty]
    public bool DeferEvaluation { get; set; }

    //  
    // Summary:
    //     Gets or sets the function to compute the value.
    [ScriptName("read")]
    [IntrinsicProperty]
    public Func<T> GetValueFunction { get; set; }

    //
    // Summary:
    //  Gets or sets the function to compute the value.
    [ScriptName("write")]
    [IntrinsicProperty]
    public Action<T> SetValueFunction { get; set; }

    //
    // Summary:
    //     Gets the model instance which acts as 'this' in the get value function.
    [IntrinsicProperty]
    [ScriptName("owner")]
    public object Model { get; set; }
}

I ended up making a new 'Import Library' Project
and defined the missing pieces.

namespace KnockoutApi
{
    [Imported]
    [IgnoreNamespace]
    [ScriptName("ko")]
    public static class Ko
    {
        /// <summary>
        /// Creates an observable with a value computed from one or more other values.
        /// </summary>
        /// <typeparam name="T">The type of the observable value.</typeparam>
        /// <param name="options">Options for the dependent observable.</param>
        public static DependentObservable<T> DependentObservable<T>(DependentObservableWritableOptions<T> options)
        {
            return null;
        }
    }
}


[IgnoreNamespace]
[Imported]
[ScriptName("Object")]
public class DependentObservableWritableOptions<T>
{
    public DependentObservableWritableOptions()
    { }

    // Summary:
    //     Gets or sets whether the evaluation should be deferred, i.e. not performed
    //     when the observable is first created.
    [IntrinsicProperty]
    public bool DeferEvaluation { get; set; }

    //  
    // Summary:
    //     Gets or sets the function to compute the value.
    [ScriptName("read")]
    [IntrinsicProperty]
    public Func<T> GetValueFunction { get; set; }

    //
    // Summary:
    //  Gets or sets the function to compute the value.
    [ScriptName("write")]
    [IntrinsicProperty]
    public Action<T> SetValueFunction { get; set; }

    //
    // Summary:
    //     Gets the model instance which acts as 'this' in the get value function.
    [IntrinsicProperty]
    [ScriptName("owner")]
    public object Model { get; set; }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文