![]() ![]() In this project I had LiveView enabled already. This is where LiveView steps in! We can create a snappy SPA feel without having to write any javascript at all! Let’s explore how this would work. So if we want to get a more SPA feel to our sign up flow, we’d have to add some js sprinkles. Bulma doesn’t come with any javascript included. one for student registration and one for teacher registration. While you were not watching I have added the Bulma css framework to our app and we’ll use that to create a registration page that has 2 tabs. In this post we’ll explore how we can let these different types of users register for an account. Secondary Context, but not from any Schemas.In the last post we configured our app to be able to handle sign up of different user roles. A Primary Context can call functions in any I think of the Primary Context, Secondary Context and Schema as three individual Secondary Contexts within that Primary Context - and I do view the relationshipīetween Primary and Secondary Contexts as a “container” - to the rest of theĪpplication, those Secondary Contexts (and their associated Schemas) are totally Nothing outside of this Primary Context should call any of the functions in any This is where, in my propsal here, the real context boundary takes place. download_posts_for ( user ) |> FacebookPosts. bulk_create ( user ) user |> APIs.Facebook. download_posts_for ( user ) |> TwitterPosts. facebook_posts end def download_all_posts_for ( user ) do user |> APIs.Twitter. ![]() Every publicįunction in this module should return an %Ecto.Changeset def all_posts_for ( user ) do user = user |> Users. Later), and no validations in controllers or things like that. No random changeset generation in Secondary Contexts (we’ll talk about those ![]() That go in this file, and this file is the only place those things should go. Validations you might need to do on that resource. You define that schema, any changesets that you might need to generate, and any Let’s take a sort of social media aggragator as our example app for today.Įach “resource” that has an Ecto schema gets it’s own Schema file. Ok, let’s begin! 1) Resources have Schema files, and those contain only schema definitions, type definitions, validations and changeset functions These rules actually work then they’re not worth all that much (which willįrankly never happen), but maybe, if we all talk about them, we can come up Should end up with lots of small functions that can easily be composed together,Īnd this is a very good thing to strive for.īut really, this is really just a proposal to get these ideas out into theĬommunity and hopefully spark some debate. Think these rules are solid and should hold up. However, I do feel that on a theoretical level I Production application, though, so I can’t say for sure what issues might crop If you like these rules, try them out! I haven’t tried them out in a large Your contexts in an application using Ecto. Specifically I’ll be talking about how to structure Versions 1.3 or higher that’s a little different from what’s explained in the So, today, I’m going to propose a set of rules for structuring Phoenix apps on Rules keep me from being overwhelmed by Analysis But I find having rules - even arbitrary rules! - really helpful when I’m Sometimes the rules themselvesĪren’t that good, and in that case it’s cool to throw them out all together andĬreate some new rules based on what you learned from the failings of the old Rules when we’re writing software, and that’s ok. You, and I like my decisions to be easy to make. Decision making is way easier when there are rules there to guide Menu A Proposal for Some New Rules for Phoenix Contexts ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |