Comments (5)
@zewa666 Do you have a few minutes to extend this section of the docs per @baerrach βs suggestion? Heβs a new user coming to Aurelia and has been helping us to improve the docs π
from documentation.
Oki doki will do
from documentation.
@baerrach the story as stated will startup with a intial state propagation, that is once you setup the plugin in your main.ts. Depending on how you build your app there are multiple ways to solve that part as the correct timing is heavily dependent on your app. E.g there might be a wizard/login popping up first and only after that you enter the actual app where you'd want to kick in the localStorage. So it's a bit hard to give a generic solution.
The most generic one, for a simplistic app would be to register the middleware only after the first state got dispatched (namely the initial state).
constructor(private store: Store<State>) {
this.store.state.pipe(take(1)).subscribe(() => this.store.registerMiddleware(localStorageMiddleware, MiddlewarePlacement.After, { key: 'my-storage-key' });)
}
connectTo ain't gonna play along with that at all since it's meant to setup a general subscription without the chance for fine-grained control.
What is your thinking about this @baerrach? Go along and just post the above sample? In this case I'd convert the info box to a normal text.
from documentation.
The problem also includes @connectTo
as it feels like an easy win, but doesn't look like it will scale as my app gets more complicated.
Its referenced an awful lot prior to the problem of local storage of state.
It would be great if there was some way to fix the problem using @connectTo
somehow.
It is enough to include your thoughts on a simple generic solution and hints that a more complicated app might need to hook in at different points in the lifecycle.
When that happens does that mean I need to manually recreate the @connectTo
help?
What other "eject" points are people going to hit with @connectTo
?
If I'm always going to be ejecting then I wonder whether its worth even starting with @connectTo
.
I don't have an answer for that, I'd be leveraging the wisdom of Aurelia experts.
from documentation.
Well its a bit of a mixed feeling here. People are wanting to abuse @connectTo
for something it's clearly not. Its essentially a shortcut which does save you writing a bit more boilerplate, makes sure you don't forget to unsubscribe and that's it.
The given solution from my previous comment still also applies to using connectTo. Nothing hinders you to create additional subscriptions. Addtionally, by using take(1) you also don't need to care about unsubscribing as the observable will be auto-disposed.
The question about ejecting goes more towards your use cases. I'd say, following along a pareto 80% of your VMs are going to be small, so connectTo is certainly a good fit. But for specific parts, e.g the App.js/ts where you'll likely going to do more stuff you most likely will sooner or later switch to the manual subscriptions.
My personal opinion? Always manually subscribe and be disciplined enough to handle unsubscriptions ;)
from documentation.
Related Issues (20)
- Binding basics doc typo HOT 2
- Mistakes in documentation in fundamentals chapter using webpack HOT 5
- Documentation for Observing Collections shows Typescript language elements in EsNext View HOT 1
- Dependency injection section: explicitly mention ordering of constructor params HOT 4
- Add links to Push State requires server side support documentation HOT 3
- Aurelia validation docs - configuration in .json still needed? HOT 1
- Testing Components is out of sync with latest Aurelia HOT 5
- Testing Components > Manually handling lifecycle is not complete HOT 6
- Testing > DI dependencies HOT 1
- Testing the Aurelia Skeleton Navigation App no longer works HOT 1
- Troubleshooting pages HOT 1
- Minor typo in Contact Manager tutorial HOT 4
- Improving vCurrent docs HOT 9
- idiomatic Aurelia
- Point from HTTP-Client docs to DI
- Remove reference to, or even warn about, using immer and binding with aurelia-store HOT 1
- Contact Manager Tut: Building the Application Shell: Minor issues
- Assets file not working with Chrome HOT 2
- Tutorial contains broken link to App Configuration and Startup HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from documentation.