Giter Site home page Giter Site logo

Comments (3)

marshallswain avatar marshallswain commented on June 23, 2024

Being able to pass a viewModel instance to the connect function is probably the best solution to this, but we probably will have to fix enumerability of DefineMap instance props.

Extracting from the DOM would only be a somewhat less messy solution for the top level component. For components that aren't calling ReactDOM.render themselves, it would be nothing but messy.

from react-view-models.

BigAB avatar BigAB commented on June 23, 2024

I think you just need to rethink what you are doing here.

You almost certainly don't want get the viewModel off the DOM, this is React, the DOM has been extracted away.

If you needed access to the viewModel from an parent component you could use a ref to get the component and then access it at component.viewModel.

But for your use case, what you want to do is but the message, outside of the component viewmodel, in it's own state (or pass it through components all the way down).

import AppHome from './app.jsx';
import compute from 'can-compute';

export const message = compute('Hello, Feathers!');

export const ViewModel = DefineMap.extend({
  get message() {
     return message();
  },
  changeMessage () {
    message('Hello, Marshall!')
  }
});

const AppContainer = connect(ViewModel, AppHome);

...now you could export message from the AppContainer:

import { message } from '/components/AppContainer';

...or more likely you would have some model or something seperate that had message in it, that you would export and pass around.

RE: routing
As discussed on a call, the best way to connect a router is to use the router.data as a property on the viewmodel, or use derived values from the router.data as appropriate.

Let me know if you want to discuss more or if this issue can be closed.

from react-view-models.

marshallswain avatar marshallswain commented on June 23, 2024

Very nice. Yeah, I figured out the routing demo after I posted this, which works wonderfully. Between that and the examples you've posted, there's just enough flexibility to do pretty much anythingπŸ‘πŸŽ‰

from react-view-models.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.