Adding a template to React Component - meteor-accounts

Im using the login example from the Meteor React Tutorial
meteor add accounts-ui accounts-password
Its all ok but Im trying to find the file and change it but I dont know where is it.
This is my code:
import { Blaze } from 'meteor/blaze';
export default class AccountsUIWrapper extends Component {
componentDidMount(){
this.view = Blaze.render(Template.loginButtons,
ReactDOM.findDOMNode(this.refs.container));
}
componentWillUnmount(){
Blaze.remove(this.view);
}
render(){
return <span ref="container"/>
}
}
And i have installed meteor add useraccounts:materialize
How can I put the template on this?

You need to put your component inside /imports/ui/ directory and name the file as AccountsUIWrapper.jsx
So it will be saved as /imports/ui/AccountsUIWrapper.jsx.
Then you can import your wrapped component inside /imports/ui/App.jsx file with:
import AccountsUIWrapper from './AccountsUIWrapper.jsx';
And then use it in your React render function in the same file as:
<AccountsUIWrapper />
The tutorial lays it out pretty clearly, including all the filenames and locations. You should be able to access their GitHub repository for the same.
If you want, for reference, you can also take a look at my code at this particular step back when when I did this tutorial myself.
Update: For useraccounts:materialize
The useraccounts:materialize package that you have mentioned depends on useraccounts:core package as its base. So you cannot apply useraccounts:materialize to default meteor accounts package directly.
Follow the instructions on useraccounts:core to set it up. You may need to remove accounts-ui as well, as it would likely clash with the above packages.
Then, go through the documentation for useraccounts that shows how to render their accounts template in Blaze.
After that, using the same way as shown in the tutorial, you should be able to create a new React wrapper for useraccounts:materialize Blaze template.
Here are links to boilerplate useraccounts:materialize code for Iron Router and Flow Router. From these you can take reference for the Blaze template code, which you can then wrap in React:
Boilerplate with iron:router
Boilerplate with FlowRouter

Related

Creating custom plugin for Converse.js 9.1.1

I downloaded conversejs 9.1.1 and I am trying to learn the plugin architecture by making my own custom plugin. I looked at the http-auth plugin here to see how to add a plugin.
https://github.com/conversejs/community-plugins/tree/master/packages/http-auth
To install the plugin it directs me to the instructions here:
https://m.conversejs.org/docs/html/plugin_development.html
I understand I have to modify my webpage to whitelist the plugin, but for some reason I can't grok a few things. Here is my awesome plugin which resides in a file called Hello-World.js
import { converse } from "#converse/headless/core";
const plugin = {
initialize() {
console.error("Hello World!")
}
}
if (typeof converse === "undefined") {
window.addEventListener(
'converse-loaded',
() => converse.plugins.add("Hello-World", plugin)
);
} else {
converse.plugins.add("Hello-World", plugin);
}
The htpp-auth.js has no imports, but WebStorm was complaining that converse was unknown so I had to add the import. Why does the http-auth plugin not have to do that?
I am not sure where the plugin code is supposed to live. I added Hello-World under src/plugins/Hello-World. Is this correct?
Maybe related to above, but to get the plugin to actually run in addition to whitelisting it in my webpage I had to modify converse.js and add import "./plugins/Hello-World/Hello-World.js" which makes me think I am missing something obvious as I would think adding a plugin shouldn't require you to change the base code.
If it matters I am testing my plugin by running make serve in the conversejs directory and directing my web-browser (Chrome) to localhost:8000/fullscreen.html
Thanks, Wray
The htpp-auth.js has no imports, but WebStorm was complaining that converse was unknown so I had to add the import. Why does the http-auth plugin not have to do that?
converse is available as a global once converse.js has been loaded via the <script> tag.
That's why there's the if (typeof converse === "undefined") { check at the end of the plugin. It waits for converse.js to be loaded if converse isn't yet defined.
I am not sure where the plugin code is supposed to live. I added Hello-World under src/plugins/Hello-World. Is this correct?
Most community plugins are developed in such a way that they're loaded separately via <script> tags. If you do it like that, it doesn't matter where they live.
Maybe related to above, but to get the plugin to actually run in addition to whitelisting it in my webpage I had to modify converse.js and add import "./plugins/Hello-World/Hello-World.js" which makes me think I am missing something obvious as I would think adding a plugin shouldn't require you to change the base code.
You can do it like that if you want to include your plugin inside a custom build of Converse, then you can also import stuff from converse.
The alternative is to load your plugin separately via a <script> tag, but then you can't import stuff and have to use the converse global and the closured _converse object that is passed to your plugin's initialize function.

I want to export my whole code base like a package or something like a module that I can import

I created an app for a small group of people. I created a lot of widgets/pages and models. Now another group asked if I could make them the app too. I could create a new project and copy/paste al stuff in there, but more groups want this app, and its a lot of work.
My idea was to create something like a package or export the whole code base to another destination, so that I only need to edit one code base and it changes on all app instances. For the new group I only need to change the API URL and some images which can be changed in pub spec.yaml and main.dart. Do you have a working solution for this?
Please read those articles about creating new package:
Flutter Website: link
Tutorial: link
Also, Pay attention to what is the supported platforms in you package and test it with each platform. You can also publish it to Pub.Dev if you want. but must be on GitHub first.

Is it possible to import a single file from material library to access its private fields?

I want to access a file from material.dart library ('src/material/search.dart';) so that I can access private fields (_somethingsomething) in it to create a widget.
I read a bit about part/part of and so on, but it seems that I am not using it properly.
Is something like this possible?
Steps: Copying a file from Flutter into your own app.
Create a file search_copy.dart, and copy the content of material's search.dart.
Remove the internal imports used in the file.
Instead add the import import 'package:flutter/material.dart' to search_copy.dart
Modify the new file according to your needs, like exposing the private field.
Import the file with a prefix import 'search_copy.dart' as search; so you don't get import conflicts with material itself.
When you want to access it do so like search.showSearch(context: context, delegate: delegate)
Note: The search.dart file is part of flutter itself which is BSD-licensed. (https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/material/search.dart)
License:
https://github.com/flutter/flutter/blob/master/packages/flutter/LICENSE
The answer is NO. And probably there is a reason why these fields are private since package owners (in this case, framework maintainers) do not want the developer to use the variables directly or change them in any way.
If you would like to adjust the code for the component in the material library, you could:
a) Create an issue under flutter repository and explain why you need to access the fields, maybe even create a POC by forking the repository and implementing your changes. The Flutter team may approve this and your changes will be a part of the framework - that's the beauty of open-source! However, there is no guarantee that it will happen.
b) Copy-paste the search.dart code to your project and adjust whatever is needed. This is a faster solution to your problem, however, now you should maintain this code by yourself, you would need to keep this component in sync with any Flutter update.

PlayFramework with Scala, WebJars, ReactJS and RequireJS?

I am looking for an example about combining the four technologies in the title :) I have a working ReactJS application using Play, Scala and WebJars, it's here on GitHub.
Now I would like to add RequireJS, but I'm not sure how to go, especially because it seems to require a different JSXTransformer? If anybody has a pointer (or even a PR) it would be very appreciated.
This is not the easiest thing to do, but I was able to pull it off. I will give you some tips here. I also uploaded my own project to github. This is a very simple snake game built using React and RequireJs. It based on Webjars and Play Framework.
Remember that RequireJs is part of Play Framework. Here's a step by step guide to create React/RequireJs/WebJars/Play integration:
In your plugins.sbt add addSbtPlugin("com.github.ddispaltro" % "sbt-reactjs" % "0.5.2"). This is a plugin which transforms JSXes into JSes and also strips flow types if you want that.
In your main scala.html file add #helper.requireJs(core = routes.WebJarAssets.at(WebJarAssets.locate("require.js")).url, module = routes.Assets.at("javascripts/main").url). This will add add a script tag with data-main and src attributes that are used to bootstrap your RequireJs app.
Create react.js file in your assets/javascripts folder:
define(['../lib/react/react-with-addons'], function(React) {
window.React = React;
return React;
});
Create main.jsx file in your assets/javascripts folder:
require.config({
// standard requirejs config here
});
require(['react', 'components/YourComponent'], function(React, YourComponent) {
'use strict';
$(document).ready(function() {
React.render(<YourComponent />, document.getElementById('container'));
});
});
Your standard React component goes to assets/javascripts/components/YourComponent.jsx and is defined like standard RequireJs module. Remember to return a React class:
define(function(require) {
var React = require('react');
var AnotherComponent = require('components/AnotherComponent');
return React.createClass({ ... });
}
I hope that helps. If you have any questions, please let me know.
Someone said to have got the text plugin working with sbt-rjs: https://groups.google.com/forum/#!topic/play-framework/F789ZzTOthc
I would attempt with the text plugin first, as it's the simplest plugin of all, right? Once this is successful, move on to the JSX plugin:
https://github.com/philix/jsx-requirejs-plugin
Have a look at: https://github.com/nemoo/democratizer
This is an example project that uses play framework, scala, slick, mysql as a restful backend.
The client is a javascript single page application (SPA) written in react. It uses react router for client site routing and ES6 javascript.
The build process combines webpack and play activator which enables simple automatic browser refresh for server and client side code.

How should I import a component from my addon into the addon's dummy test?

I'm writing an addon that defines a StickyHeaderListComponent under addon, and import it according to the Components section of the addons section of the guides.
I'd like to write some tests + use the dummy app, but the dummy app doesn't have access to {{sticky-header-list}}. How can I import it?
The app folder is merged into the application which consumes the addon during the build.
So, The file sticky-header-list.js should be under app/components.
Best practice is to write a mixin which will include the entire code of the component under addon/mixins
// addon/mixins/sticky-header-list.js
export default Ember.Mixin.create({
//Put all the component code here
});
And the actual component will be
// app/components/sticky-header-list.js
import StickyHeaderListMixin from '<your-addon-name>/mixins/sticky-header-list';
export default Ember.Component.extend(StickyHeaderListMixin);
In that way, a developer that will install your addon can choose to use the mixin, since the component code is not available at dev time.
The mixin will be importable under the path <your-addon-name>/mixins/sticky-header-list.js.
You can see an example in my ember-cli-lightbox addon.