首页 \ 问答 \ 是否必须将Redux与React-Native一起使用?(Is it mandatory to use Redux with React-Native?)

是否必须将Redux与React-Native一起使用?(Is it mandatory to use Redux with React-Native?)

一段时间以来,我正在学习React-native。 我发现redux非常令人困惑。 当我来自Java和Angular背景时,这是一种完全不同的思考应用程序结构的方式。 无论如何我想知道是否必须只使用反应原生的Redux? 或者是否也可以使用一些更接近MVC模式的其他框架。


For some time now, I am learning React-native. I find redux very confusing. It's a completely different way of thinking about your application structure as I come from Java and Angular background. Any way I was wondering if it is mandatory to use Redux only with react-native? or is it also possible to use some other framework, which is more close to the MVC pattern.


原文:https://stackoverflow.com/questions/41206773
更新时间:2023-11-07 12:11

最满意答案

我看了一下MVC的源码,看看我能否找出如何做到这一点。 控制器上下文,视图,视图数据,路由数据和html渲染方法之间似乎有很紧密的耦合。

基本上为了实现这一点,您需要创建所有这些额外的元素。 其中一些是相对简单的(如视图数据),但有些更复杂 - 例如,路由数据将考虑当前WebForms页面被忽略。

大问题似乎是HttpContext - MVC页面依赖于HttpContextBase(而不是像WebForms这样的HttpContext),并且同时实现IServiceProvider它们不相关。 MVC的设计者作出了一个故意的决定,不会改变传统的WebForms来使用新的上下文基础,但是它们提供了一个包装器。

这可以让您将部分视图添加到WebForm中:

public class WebFormController : Controller { }

public static class WebFormMVCUtil
{

    public static void RenderPartial( string partialName, object model )
    {
        //get a wrapper for the legacy WebForm context
        var httpCtx = new HttpContextWrapper( System.Web.HttpContext.Current );

        //create a mock route that points to the empty controller
        var rt = new RouteData();
        rt.Values.Add( "controller", "WebFormController" );

        //create a controller context for the route and http context
        var ctx = new ControllerContext( 
            new RequestContext( httpCtx, rt ), new WebFormController() );

        //find the partial view using the viewengine
        var view = ViewEngines.Engines.FindPartialView( ctx, partialName ).View;

        //create a view context and assign the model
        var vctx = new ViewContext( ctx, view, 
            new ViewDataDictionary { Model = model }, 
            new TempDataDictionary() );

        //render the partial view
        view.Render( vctx, System.Web.HttpContext.Current.Response.Output );
    }

}

然后在您的WebForm中,您可以这样做:

<% WebFormMVCUtil.RenderPartial( "ViewName", this.GetModel() ); %>

I had a look at the MVC source to see if I could figure out how to do this. There seems to be very close coupling between controller context, views, view data, routing data and the html render methods.

Basically in order to make this happen you need to create all of these extra elements. Some of them are relatively simple (such as the view data) but some are a bit more complex - for instance the routing data will consider the current WebForms page to be ignored.

The big problem appears to be the HttpContext - MVC pages rely on a HttpContextBase (rather than HttpContext like WebForms do) and while both implement IServiceProvider they're not related. The designers of MVC made a deliberate decision not to change the legacy WebForms to use the new context base, however they did provide a wrapper.

This works and lets you add a partial view to a WebForm:

public class WebFormController : Controller { }

public static class WebFormMVCUtil
{

    public static void RenderPartial( string partialName, object model )
    {
        //get a wrapper for the legacy WebForm context
        var httpCtx = new HttpContextWrapper( System.Web.HttpContext.Current );

        //create a mock route that points to the empty controller
        var rt = new RouteData();
        rt.Values.Add( "controller", "WebFormController" );

        //create a controller context for the route and http context
        var ctx = new ControllerContext( 
            new RequestContext( httpCtx, rt ), new WebFormController() );

        //find the partial view using the viewengine
        var view = ViewEngines.Engines.FindPartialView( ctx, partialName ).View;

        //create a view context and assign the model
        var vctx = new ViewContext( ctx, view, 
            new ViewDataDictionary { Model = model }, 
            new TempDataDictionary() );

        //render the partial view
        view.Render( vctx, System.Web.HttpContext.Current.Response.Output );
    }

}

Then in your WebForm you can do this:

<% WebFormMVCUtil.RenderPartial( "ViewName", this.GetModel() ); %>

相关问答

更多
  • 我看了一下MVC的源码,看看我能否找出如何做到这一点。 控制器上下文,视图,视图数据,路由数据和html渲染方法之间似乎有很紧密的耦合。 基本上为了实现这一点,您需要创建所有这些额外的元素。 其中一些是相对简单的(如视图数据),但有些更复杂 - 例如,路由数据将考虑当前WebForms页面被忽略。 大问题似乎是HttpContext - MVC页面依赖于HttpContextBase(而不是像WebForms这样的HttpContext),并且同时实现IServiceProvider它们不相关。 MVC的设 ...
  • 几天前在https://drupal.org/node/2023489发布的webform 7.x-4.0-alpha8内置了更多的视图支持。您可以选择要在视图中查看的提交数据值。 webform 7.x-4.0-alpha8 released just a few days ago at https://drupal.org/node/2023489 has more Views support built in. You can choose the submission data value that ...
  • 阅读本页未正确加载Google地图。 有关技术详细信息,请参阅JavaScript控制台 换句话说,您应该获得一个API密钥才能使用该地图,并在代码中进行设置 Read This page didn't load Google Maps correctly. See the JavaScript console for technical det ...
  • 哦Duh,阅读错误信息...... 我改变了webform的第一行: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="menu.aspx.cs" Inherits="System.Web.Mvc.ViewUserControl" %> 对此: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="menu.aspx.cs" Inherits="System.Web.Mvc.Vi ...
  • 我最终使用javascript通过他们的ID找到角度下拉列表,获取他们的值并在帖子上更新一些隐藏的输入。 它可能不优雅但有效。 I eventually used javascript to find the angular dropdowns by their IDs, get their values and update some hidden inputs on post. It may not be elegant but worked.
  • 来自部分视图助手的文档 : Partial view helper用于在其自己的变量范围内呈现指定的模板。 主要用途是可重用的模板片段,您无需担心变量名称冲突。 此外,它们允许您指定特定模块的部分视图脚本。 然后,您将使用以下命令从视图脚本中调用它: partial('partial.phtml', array( 'from' => 'Team Framework', 'subject' => 'view partials')); ?> 如果您不需要单独 ...
  • 如果您只需要在其下方添加文本,那么您可以做的一件事就是将描述添加到表单的最后一个字段,尽管它可能不是您想要的大小。 或者您可以覆盖主题: 在D6中,在主题中使用theme_webform_element()主题功能来覆盖主题的template.php 在D7中,在主题中使用theme_webform_element_wrapper()主题功能来覆盖主题的template.php 使用主题开发人员模块http://drupal.org/project/devel_themer ,它像Firebug一样工作,以 ...
  • 答案是通过调用@Html.Action() 。 听起来你走在正确的轨道上。 关键是尝试不要传递多个模型,使模型复杂化,或者不必要地使用ViewBag。 相反,只要您想在每个页面上获取信息,请从_Layout调用操作。 例如,您可能有一个名为PartialsController或SharedController的控制器。 public class PartialsController : Controller { [ChildActionOnly] public ActionResult Us ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)