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

Examples from readme #304

Closed
Mika83AC opened this issue Apr 28, 2017 · 7 comments
Closed

Examples from readme #304

Mika83AC opened this issue Apr 28, 2017 · 7 comments
Labels

Comments

@Mika83AC
Copy link

Hello everyone,

sorry, but am I just blind/an idiot/dumb or aren't the examples found in the readme working?

I installed stampit via bower via "bower install stampit" an have the following code:

<script src="bower_components\stampit\stampit.js"></script>
<script>
// Some privileged methods with some private data.
const Availability = stampit().init(function() {
  var isOpen = false; // private
  ....

When executing this in Chrome, it says:
Uncaught TypeError: stampit is not a function at stampit.html:5

But when typing "stampit" into Chrome Dev Tools console, it shows me that stampit is available with all it's methods (compose, composers, conf ...).

So what the hell is wrong?

Thx in advance!
Regards,
Michael

@koresar
Copy link
Member

koresar commented Apr 28, 2017 via email

@danielkcz
Copy link
Contributor

danielkcz commented Apr 28, 2017

@Mika83AC Where do you have these script tags? Both in the head? In case you include both at the same spot, chances are that your "app code" is executed before stampit script is loaded and parsed. However accessing it later in the console works ok. You can investigate this behavior in Network tab of developer tools.

The safest path is load external scripts in head tag and your logic at the end of the body.

@Mika83AC
Copy link
Author

Mika83AC commented May 2, 2017

@koresar Hm... I think I'm not in a position to help as I'm a JS and StampIt newbie ... :( Really have no idea what might be wrong.

@FredyC Even this is not working for me. Here is my example done as I understood your advice:

<!doctype html>
	<head>
		<meta charset="utf-8">
		
		<script src="bower_components\stampit\stampit.js"></script>
	</head>
	<body>
		Test
	</body>
	<script>
	// Some privileged methods with some private data.
	const Availability = stampit().init(function() {
	  var isOpen = false; // private

	  this.open = function open() {
		isOpen = true;
		return this;
	  };
	  this.close = function close() {
		isOpen = false;
		return this;
	  };
	  this.isOpen = function isOpenMethod() {
		return isOpen;
	  }
	});

	// Here's a stamp with public methods, and some state:
	const Membership = stampit({
	  methods: {
		add(member) {
		  this.members[member.name] = member;
		  return this;
		},
		getMember(name) {
		  return this.members[name];
		}
	  },
	  properties: {
		members: {}
	  }
	});

	// Let's set some defaults:
	const Defaults = stampit({
	  init({name, specials}) {
		this.name = name || this.name;
		this.specials = specials || this.specials;
	  },
	  properties: {
		name: 'The Saloon',
		specials: 'Whisky, Gin, Tequila'
	  }
	});

	// Classical inheritance has nothing on this.
	// No parent/child coupling. No deep inheritance hierarchies.
	// Just good, clean code reusability.
	const Bar = stampit(Defaults, Availability, Membership);

	// Create an object instance
	const myBar = Bar({name: 'Moe\'s'});

	// Silly, but proves that everything is as it should be.
	myBar.add({name: 'Homer'}).open().getMember('Homer');
	</script>

</html>

Still the error "Uncaught TypeError: stampit is not a function at index.html:12".

@danielkcz
Copy link
Contributor

danielkcz commented May 2, 2017

@Mika83AC Where did you actually get that stampit script? Is it freshly installed from bower or did you made a copy from somewhere? Can you please try this live URL instead? https://npmcdn.com/[email protected]/dist/stampit.umd.min.js

@Mika83AC
Copy link
Author

Mika83AC commented May 2, 2017

@FredyC I freshly installed it via bower as described in the readme: "bower install stampit". This morning (before posting here) I performed a "bower update" to be sure to be on the latest version.

Using the CDN link you posted results in the same error. I've put my "example" on my server so you can have a direct look at it: http://divelop.de/stampit/

As I'm using the latest Chrome, I don't think it can/will be a browser compatibility issue.

@danielkcz
Copy link
Contributor

I see, there seems to be some issue unrelated to your code indeed. Quick workaround is simply to call stampit.init instead of stampit().init

@koresar Once again there is exported object with default instead of a function being exported. I though we solved this before, not sure if you were doing some changes there.

@koresar koresar added the bug label Jul 9, 2017
@koresar koresar mentioned this issue Oct 21, 2017
@koresar
Copy link
Member

koresar commented Nov 9, 2017

Fixed with stampit v4.

@koresar koresar closed this as completed Nov 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants