Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 20:11

    matthewp on master

    Update dist for release (compare)

  • 20:11

    matthewp on v6.2.0

    Update dist for release 6.2.0 (compare)

  • 20:05

    matthewp on master

    Fix bundlesize (compare)

  • 19:22

    matthewp on can-observable-bindings-1.3.0

    (compare)

  • 19:22

    matthewp on master

    fix(package): update can-observ… Set new bundle sizes Merge pull request #5389 from c… (compare)

  • 19:22
    matthewp closed #5389
  • 19:09
    matthewp commented #5389
  • 18:33

    matthewp on can-attribute-observable-2.0.1

    (compare)

  • 18:33

    matthewp on master

    fix(package): update can-attrib… Increase the bundlesize Merge pull request #5394 from c… (compare)

  • 18:33
    matthewp closed #5394
  • 17:59
    matthewp synchronize #5394
  • 17:59

    matthewp on can-attribute-observable-2.0.1

    Increase the bundlesize (compare)

  • 17:42
    matthewp synchronize #5389
  • 17:42

    matthewp on can-observable-bindings-1.3.0

    fix(package): update can-observ… Set new bundle sizes (compare)

  • 17:26
    greenkeeper[bot] labeled #5394
  • 17:26
    greenkeeper[bot] opened #5394
  • 17:26

    greenkeeper[bot] on can-attribute-observable-2.0.1

    fix(package): update can-attrib… (compare)

  • 17:15

    matthewp on can-stache-element-1.0.2

    (compare)

  • 17:15

    matthewp on master

    fix(package): update can-stache… Merge pull request #5387 from c… (compare)

  • 17:15
    matthewp closed #5387
Jim O'Harra-Sutton
@Psykoral
it's defined, but it's set to null until it gets a value
yeah, it's in the DefineMap directly
Brad Momberger
@bmomberger-bitovi
OK. I think there's something else going on here but I can't say what with the information provided. Possibly your Stache is looking at a different object than the one you intended.
Jim O'Harra-Sutton
@Psykoral
so here's my real example:
// state.js

export const AppState = DefineMap.extend({seal: false},{
  authToken: {
        type: 'string',
        value: null
    }
});

// footer.js
import AppState from '~/state';

export const ViewModel = DefineMap.extend({ seal: false },{
    loggedIn: {
        get () {
            return (AppState.authToken !== null);
        }
    },
    isAdmin: 'string',
    year: 'string'
});

// Stache:

{{#if loggedIn}}
  <li>
    <a href="{{routeUrl page='logout'}}">Logout</a>
  </li>
{{else}}
  <li>
    <a href="{{routeUrl page='login'}}">Login</a>
  </li>
{{/if}}
I'm essentially trying to get the Footer to change the link based on the state of being logged in or not
Brad Momberger
@bmomberger-bitovi
I see the problem immediately.
AppState as you have made it is a constructor class for your app state.
const AppStateClass =  DefineMap.extend({seal: false},{
  authToken: {
        type: 'string',
        value: null
    }
});
export const AppState = new AppStateClass();
Jim O'Harra-Sutton
@Psykoral
sorry, that's not all of it though, it actually exports a new AppState() that the whole app shares
Brad Momberger
@bmomberger-bitovi
OK, but your loggedIn getter is still looking at the class
Jim O'Harra-Sutton
@Psykoral

yep that's almost exactly what I have, I just still called is AppState

export default new AppState();

does that work or should I change the name and export?
Brad Momberger
@bmomberger-bitovi
ok, so the default export from state.js is new AppState() but it also exports the AppState class as a named export?
Jim O'Harra-Sutton
@Psykoral
yeah I'm probably confusing it with that, I've changed it to AppStateClass () to avoid that, good call
Brad Momberger
@bmomberger-bitovi
OK. I would definitely still check it from the console and see if all the values in the model and viewmodel are correct.
Do you know the tricks for getting access to modules in the dev console?
Jim O'Harra-Sutton
@Psykoral
not exactly but I do have a debugger setup that I can turn on that'll spit out values at the right times so I can tell what they are
Brad Momberger
@bmomberger-bitovi
For any project using Steal as its dependency manager, you can use e.g. System.import('~/state').then(c => window.AppState = c.default }) to export the default export of state.js to the window.
If instead you're doing a global build with steal-tools, all of your modules are hosted in window._define.modules
Brad Momberger
@bmomberger-bitovi
So if you're logged in, the default export of state.js should have a non-null authToken and if you get the canViewModel() function from System.import('can-view-model'), calling it on your footer component element (canViewModel("my-footer") if your footer component tag is called "my-footer") will show you the instance of the ViewModel class that was created for it.
You can then check the value of loggedIn on that ViewModel instance
Jim O'Harra-Sutton
@Psykoral
sorry, I think I broke something in my session.js with that name change
Brad Momberger
@bmomberger-bitovi
Interesting.
I'm wondering if session.js was operating on the wrong object.
Jim O'Harra-Sutton
@Psykoral
I guess it was, which is weird.... because it was totally working lol
Brad Momberger
@bmomberger-bitovi
Jim O'Harra-Sutton
@Psykoral
// session.js

import AppState from '~/_app/js/state';
console.log('AppState',AppState);

AppState undefined
lol yeah exactly.
Brad Momberger
@bmomberger-bitovi
And you definitely have a default export in state.js?
Jim O'Harra-Sutton
@Psykoral
yep, but should it be something other than AppState?
export const AppState = new AppStateClass();
export default AppState;
Brad Momberger
@bmomberger-bitovi
That should work fine.
Though you could also try import {AppState} from '~/_app/js/state'; just for shits and giggles.
(that syntax imports the named export instead of the default)
The one other possibility is that these files have a circular dependency. Steal resolves that by initially letting circular deps be undefined, then letting the scripts create their exports.
Which means you can still use imports from a circular dependency, but not synchonously.
Jim O'Harra-Sutton
@Psykoral
ERROR: Failed promise: TypeError: Error evaluating myapp@2.0.0#_app/js/state
Error evaluating myapp@2.0.0#models/session
AppState is undefined
that's with import {AppState} from '~/_app/js/state';
Brad Momberger
@bmomberger-bitovi
Is it salient that in footer.js you were importing from "~/state"?
Jim O'Harra-Sutton
@Psykoral
ha, wow
I mean footer.js just had import AppState from "~/_app/js/state"; in it but was never being used. Didn't think that would be undefined, but I commented that out and no errors now
Jim O'Harra-Sutton
@Psykoral
OK so progress... errors are all gone
I login, AppState.authToken get updated, but the getters aren't firing
Brad Momberger
@bmomberger-bitovi
Can you get the view model from your footer or any component that has a dependent getter and see what its value is?
Jim O'Harra-Sutton
@Psykoral
Oh I think I see what it was, I was setting the this.sessionState = false;which was changed to the getter instead
Brad Momberger
@bmomberger-bitovi
BTW getters can take set values as input as well.
Give them an argument like such:
foo: {
  get: function(lastSetValue) {
      return typeof lastSetValue !== "undefined" ? lastSetValue : this.someOtherProperty;
 }
}
So in this case, setting foo = "bar" will trigger an update. That doesn't happen when get() has zero arguments.
Jim O'Harra-Sutton
@Psykoral
sessionState: {
        get (lastSetValue) {
            return typeof lastSetValue !== 'undefined' ? lastSetValue : (AppState.authToken !== null);
        }
    },
logout () {
        //this.sessionPromise = AppState.session.destroy();
        AppState.authToken = null;
        this.debug.log('logout: AppState.authToken should be null', null);
        this.debug.log('logout: this.sessionState should be false', this.sessionState);
    }