تعیین نوع props و state در کامپوننتهای کلاسی
برای این منظور ابتدا فایل جدید src\components\BigC.tsx را ایجاد کرده و سپس توسط میانبر rcc، ساختار ابتدایی این کامپوننت را ایجاد میکنیم. در ادامه آنرا در کامپوننت src\App.tsx استفاده خواهیم کرد:
یکی از مزایای دیگر کار با تایپاسکریپت، فعال شدن intellisense مرتبط با افزونههایی مانند typescript hero و auto import است که نمونهای از آنرا در تصویر فوق مشاهده میکنید. فقط کافی است نام المان مرتبط را نوشت و سپس با استفاده از افزونههای یاد شده، به صورت خودکار import آنرا اضافه کرد.
پس از افزودن المان این کامپوننت، اگر سعی کنیم یک props را برای آن تعریف کنیم، بلافاصله خطای تعریف نشده بودن آنرا دریافت خواهیم کرد:
در اینجا نیز همانند کامپوننتهای تابعی، باید ابتدا نوع Props را تعیین کرد و تنها تفاوت آن، روش معرفی این type جدید به کامپوننت است:
import React, { Component } from "react"; type Props = { title: string; }; type State = { status: string; }; export default class BigC extends Component<Props, State> { render() { return ( <div> <h1>I'm in a class component</h1> </div> ); } }
مابقی نکات آن مانند props اختیاری و غیره، تفاوت خاصی را با کامپوننتهای تابعی که پیشتر بررسی کردیم، ندارند و یکی هستند.
مقایسهای بین Types و Interfaces
در این سری بیشتر از types استفاده شد، تا اینترفیسهای تایپاسکریپت. برای مثال بجای نوع زیر:
type State = { rValue: boolean; };
interface State { rValue: boolean; }
در تایپاسکریپت، از type بیشتر برای تعریف یک نوع جدید استفاده میشود، اما از اینترفیسها برای تعریف موجودیتها و entities. برای مثال از type میتوان برای تعریف نامی برای نوعهای primitive, union, intersection نیز استفاده کرد، اما اینترفیسها همواره برای تعیین نوع اشیاء مورد استفاده قرار میگیرند. نمیتوان دو نوع همنام را تعریف کرد، اما اگر دو اینترفیس هم نام را تعریف کنید، با هم یکی میشوند. نوعها برخلاف اینترفیسها قابلیت پیاده سازی نداشته و بیشتر جنبهی یک اعلان را دارند و ... در نهایت استفادهی از هر کدام بیشتر یک انتخاب شخصی است.
منابع تکمیلی
یکی از بهترین منابع تکمیلی استفادهی از TypeScript در React، مخزن کد react-typescript-cheatsheet است که به همراه مجموعهای از نکات مرتبط است.
دورهی کامل میکروسرویسها در دات نت
.NET Microservices – Full Course, Les Jackson
In this step-by-step tutorial I take you through an introduction on building microservices using .NET. As the name suggests we build everything completely from start to finish –with the full scope of the course outlined in the time-stamp section below. However, at a high-level we’ll cover:
• Building two .NET Microservices using the REST API pattern
• Working with dedicated persistence layers for both services
• Deploying our services to Kubernetes cluster
• Employing the API Gateway pattern to route to our services
• Building Synchronous messaging between services (HTTP & gRPC)
• Building Asynchronous messaging between services using an Event Bus (RabbitMQ)
This webcast is a code-focused introduction to developing workflow-enabled Microsoft Windows platform applications. We cover the basics of developing, designing, and debugging workflow solutions. Gain the knowledge and insight you need to be confident choosing workflow for everyday applications.
Intro to Windows Workflow Foundation (Part 2 of 7): Simple Human Workflow Using E-mail (Level 200)
Have you thought about how you might apply the workflow concept to e-mail? In this webcast New Zealand based regional director, Chris Auld, leads attendees through a simple worked example of the use of SMTP e-mail as part of a workflow solution. Chris demonstrates how to create custom activities to query Active Directory to retrieve user data, send e-mail, and wait for e-mail responses to continue the workflow process. This code-intensive session gives users taking their first steps with workflow a good grounding in some of the key extensibility concepts.
Intro to Windows Workflow Foundation (Part 3 of 7): Hosting and Communications Options in Workflow Scenarios (Level 300)
The session looks at options for hosting workflow applications. We cover managing events, instance tracking, and persistence, and provide a close look at the simple communications mechanisms that are available for you to use in your workflow applications.
Intro to Windows Workflow Foundation (Part 4 of 7): Workflow, Messaging, and Services: Developing Distributed Applications with Workflows (Level 300)
Web service technologies have typically taken a "do-it-yourself" approach to maintaining the interoperation state of services. Using workflow, developers now have tools that allow them to describe the long-running state of their services and delegate much of the state management to the underlying platform. Managing this state correctly becomes even more challenging in applications that coordinate work across multiple services either within an organization or at an Internet scale. This session looks at how developers who use either Microsoft ASMX or Microsoft's framework for building service-oriented applications, code-named "Indigo", can create workflow-oriented applications that are both faster to write and more manageable and flexible once deployed.
Intro to Windows Workflow Foundation (Part 5 of 7): Developing Event Driven State Machine Workflows (Level 300)
State machines used to be something that you had to first draw on paper and then implement in code. This session shows how to use technologies to create event-driven workflows and how to apply this to a typical programming problem. We introduce the concept of a flexible process and show how this can help with modeling real-world processes using state and sequential workflow. Plenty of coding is included to illustrate how you can seamlessly merge state machine design and your code.
Intro to Windows Workflow Foundation (Part 6 of 7): Extending Workflow Capabilities with Custom Activities (Level 300)
It is helpful to think of activities as controls within a workflow, similar to controls used with Microsoft ASP.NET Pages or Microsoft Windows Forms. You can use activities to encapsulate execution logic, communicate with the host and decompose a workflow into reusable components. This session examines the simple process of creating custom activities. If you want to expose activities to other developers designing workflows, you are likely to find this session valuable.
Intro to Windows Workflow Foundation (Part 7 of 7): Developing Rules Driven Workflows (Level 300)
Rules can be a powerful business tool when combined with workflow. In this session, learn how to develop more advanced activities that support the modeling of rich business behavior such as human workflow. Understand when to use rules for business logic, and see how rule policies allow for the description of sophisticated behavior in an integrated and flexible way. This session gives you an interesting insight into the power of using workflow at the core of a line of business application.
You'll often hear the terms framework
and platform
used interchangeably. This can be very confusing. You'll hear that .NET Core is a platform. Then you'll read that .NET Core is cross-platform. Next, you'll learn that .NET Core is a framework. And it doesn't help that framework is part of the name of the original full .NET Framework.
In this post, I explain the difference between frameworks and platforms and explain why sometimes you'll see .NET being referred to as a framework and other times see it referred to as a platform.