Property Included in a Flow
In the fy syntax, a property is a class mixin that defines a method annotated with @property
Python annotation to provide data to the encapsulating flow. Properties can be defined in various ways, depending on how the data is intended to be used or modified. For instance, a property might fetch data from a database or a third-party API, or it could compute data using other properties included in the flow.
Syntax
Breakdown of Syntax
flow HelloWorld_UsingGreeting -> None:
- Declares a new flow named
HelloWorld_UsingGreeting
, which is implemented as a Python class that uses property as a mixin. -> None
specifies the return type of the flow, which in this case isNone
.
- Declares a new flow named
property greeting using hello_world
- Declares a property named
greeting
with a constant value or predefined behavior.
- Declares a property named
- Code Generation:
- The fy tool generates code between
# fy:start
and# fy:end
including the class definition and the method declaration. - The generated code includes the class definition
HelloWorld_UsingGreeting_Flow
, which incorporates theGreeting_UsingHelloWorld_PropertyMixin
mixin and theFlowBase
base class. - The
Greeting_UsingHelloWorld_PropertyMixin
import statement is automatically added once in the file. When the fy tool detects this import in the code, it skips adding it again to avoid disrupting the import order. - The declaration of
__call__(self) -> None:
method.
- The fy tool generates code between
- User Input:
- The only code the user needs to write is the
flow
declaration within the"""fy
block. - After boilerplate code generation, the user can add custom functionality, such as
print(self._greeting)
.
- The only code the user needs to write is the
Summary
In fy, defining a property in a flow allows you to encapsulate data as an attribute that is used by other property and method mixins included in a flow. A flow can include property implementation that fits its needs, like fetching data from the database or providing a constant value. This makes it easy to manage state and logic in a modular and intuitive way.