Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add view controllers #407

Merged
merged 8 commits into from
Feb 19, 2023
Merged

feat: Add view controllers #407

merged 8 commits into from
Feb 19, 2023

Conversation

mikaeelghr
Copy link
Contributor

Description
Add the ability to add views.

usage:

from robyn import Robyn

app = Robyn(__file__)


@app.view("/")
def view():
    def get():
        return "Hello, world!"
    def post():
        return "Hello, world!"

app.start()

This PR fixes #221

@netlify
Copy link

netlify bot commented Feb 11, 2023

Deploy Preview for robyn canceled.

Name Link
🔨 Latest commit 4b5dd5b
🔍 Latest deploy log https://app.netlify.com/sites/robyn/deploys/63f284c7e5a2e00008f3003d

@sansyrox
Copy link
Member

Thanks for the PRs @mikaeelghr . It was amazing waking up to these happy surprises 😄

I will try to review your PRs over the course of the day.

@sansyrox
Copy link
Member

Hey @mikaeelghr ,

Thanks for the PR. I have a few suggestions for the PR. Can you write some integration tests for your code?

Second instead of creating an @app.view decorator, I wanted to add a function like app.add_view("/", view). The rationale behind that is that if a developer wants to use the decorator syntax, they will use the @get, @post, etc.

But if they want to organize their code in different files or responsibilities, they should use the view syntax and they can include the function from the module.

@sansyrox
Copy link
Member

@mikaeelghr , I have added a few tests. Everything else looks great!

@sansyrox sansyrox force-pushed the feat-221 branch 2 times, most recently from 22475fa to a17611f Compare February 18, 2023 14:42
@mikaeelghr
Copy link
Contributor Author

Thanks for the follow up @sansyrox, I was very busy this week and I couldn't add the tests.

One more thing, based on your comment, shouldn't we delete the view function on the robyn/__init__.py?

@sansyrox
Copy link
Member

Thanks for the follow up @sansyrox, I was very busy this week and I couldn't add the tests.

No worries @mikaeelghr 😄

I am actually working a lot with views today. And I realized that having this versatility(the @app.view decorator) is a nice touch. Great work! 😄

I will be pushing an update shortly

@sansyrox sansyrox force-pushed the feat-221 branch 2 times, most recently from abb6e0e to 7038cb2 Compare February 18, 2023 15:32
@sansyrox sansyrox requested a review from AntoineRR February 18, 2023 15:44
@sansyrox sansyrox force-pushed the feat-221 branch 2 times, most recently from ceff604 to 9f869b6 Compare February 18, 2023 17:29
@sansyrox sansyrox force-pushed the feat-221 branch 2 times, most recently from d8e574e to b5ad609 Compare February 18, 2023 18:17
Copy link
Collaborator

@AntoineRR AntoineRR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job! 😄 I added a few small suggestions. One last here: I would put all tests related to views in the same file, be they sync or async. This is what's done for the other features so I think it makes more sense.

robyn/__init__.py Show resolved Hide resolved
robyn/__init__.py Outdated Show resolved Hide resolved
robyn/__init__.py Outdated Show resolved Hide resolved
integration_tests/views/async_view.py Show resolved Hide resolved
integration_tests/test_sync_views.py Outdated Show resolved Hide resolved
integration_tests/test_base_url.py Outdated Show resolved Hide resolved
integration_tests/base_routes.py Outdated Show resolved Hide resolved
@sansyrox sansyrox force-pushed the feat-221 branch 3 times, most recently from fba317e to 88bf42a Compare February 19, 2023 19:54
@sansyrox
Copy link
Member

@AntoineRR , everything is resolved now. Thank you for the review 😄

Thanks for the great work again @mikaeelghr 😄

Copy link
Collaborator

@AntoineRR AntoineRR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fixes! One last thing @sansyrox, can't we merge the integration_tests/views/async_view.py and integration_tests/views/test_view.py files together? Or at least rename test_view.py to sync_view.py?

@sansyrox
Copy link
Member

@AntoineRR ,

can't we merge the integration_tests/views/async_view.py and integration_tests/views/test_view.py files together?

We can but I wanted to suggest one view per file(like react) for better organization of the code.

Or at least rename test_view.py to sync_view.py?

Done! 😄

@sansyrox sansyrox merged commit 5f437d1 into sparckles:main Feb 19, 2023
@domingues
Copy link

@mikaeelghr @sansyrox Genuine question, why not use a simple class vs doing code introspection to extract the inner functions? Can't see in each way this is a better approach.

@sansyrox
Copy link
Member

Hi @domingues 👋

We don't want to choose function base approach over class based approach. I just like to structure my code in closures sometimes and not having the ability to do that anywhere else was annoying .

We just haven't got around to implementing class-based views as of yet. 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Add views/view controllers
4 participants