Will there be an ES6 compatible module system (import/export) in iojs? - io.js

I cannot find anywhere info about what the plans will be with this ES6 feature.
It would be very useful to have something similar as in the browser.
//------ lib.js ------
export const sqrt = Math.sqrt;
export function square(x) {
return x * x;
}
export function diag(x, y) {
return sqrt(square(x) + square(y));
}
//------ main.js ------
import { square, diag } from 'lib';
console.log(square(11)); // 121
console.log(diag(4, 3)); // 5

Comment about ES6 module support from io.js core team member: https://github.com/iojs/io.js/issues/1043#issuecomment-78030670

Related

How do I generate private keys for ThunderCore from a 12-word mnemonic seed phrase exported from TrustWallet or Metamask?

I got a 12-word mnemonic seed phrase exported from TrustWallet, however, I need it as a thunderCore private key. How do I generate the thunderCore private key from it? What if the seed phrase is export from Metamask?
To generate private keys from 12-word mnemonic phrases, you need a derivation path (a string) as specified in BIP-0049.
Derivation paths used in the field:
m/44'/1001'/0'/0: uses the correct coin type for ThunderCore (1001) as registered in SLIP-0044, used by TrustWallet
"m/44'/60'/0'/0: is the derivation path used for Ethereum mainnet, used by MetaMask
Here's a self-contained example to generate private keys from the 12-word mnemonic using the ethereum-hdwallet library:
hdwallet.js
const EthereumHDWallet = require('ethereum-hdwallet')
// https://github.com/bitcoin/bips/blob/master/bip-0049.mediawiki
// https://github.com/satoshilabs/slips/blob/master/slip-0044.md
const TrustWalletHdPath = "m/44'/1001'/0'/0" // coin_type 1001 is ThunderCore, this is the recommended path
const MetaMaskHdPath = "m/44'/60'/0'/0" // coin_type 60 is really Ethereum, but MetaMask use it for all EVM compatible chains
class HdWallet {
constructor(mnemonic) {
this.mnemonic = this.mnemonic
this.w = EthereumHDWallet.fromMnemonic(mnemonic)
}
deriveUsingTrustWalletPath() {
return this.w.derive(TrustWalletHdPath)
}
deriveUsingMetaMaskPath() {
return this.w.derive(MetaMaskHdPath)
}
metaMaskAddress(index /*: number */) /*: string */ {
return '0x' + this.deriveUsingMetaMaskPath().derive(index).getAddress().toString('hex')
}
trustWalletAddress(index /*: number */) /*: string */ {
return '0x' + this.deriveUsingTrustWalletPath().derive(index).getAddress().toString('hex')
}
metaMaskPrivateKey(index /*: number */) /*: string */ {
return this.deriveUsingMetaMaskPath().derive(index).getPrivateKey().toString('hex')
}
trustWalletPrivateKey(index /*: number */) /*: string */ {
return this.deriveUsingTrustWalletPath().derive(index).getPrivateKey().toString('hex')
}
}
const fromMnemonic = (s /*: string or buffer */) => {
return new HdWallet(s)
}
module.exports = {
fromMnemonic: fromMnemonic,
}
testHdWallet.js
const assert = require('assert');
const HdWallet = require('../src/hdwallet');
const mnemonic = 'feel pulp crunch segment buzz turn organ broccoli elder ask phone limit';
describe('fromMnemonic', () => {
it('trustWalletAddress', async() => {
const w = HdWallet.fromMnemonic(mnemonic);
console.log('TrustWallet:', w.trustWalletAddress(0));
assert('0x2323Beb990514446bA4c073C2e1A4BDC0ECf06Af'.toLowerCase() ===
w.trustWalletAddress(0).toLowerCase());
});
it('metaMaskAddress', async() => {
const w = HdWallet.fromMnemonic(mnemonic);
console.log('MetaMask:', w.metaMaskAddress(0));
assert('0x9A7be7ae9a2779167bc5b64d1cC672cc5b2593e4'.toLowerCase() ===
w.metaMaskAddress(0).toLowerCase());
});
it('trustWalletPrivateKey', async() => {
const w = HdWallet.fromMnemonic(mnemonic);
console.log('TrustWallet sk:', w.trustWalletPrivateKey(0));
assert('6d7bf444545ce47d7fda9df58275f5f4dd5eb911494ab66d81f76f1aca2b763e'.toLowerCase() ===
w.trustWalletPrivateKey(0).toLowerCase());
});
it('metaMaskPrivateKey', async() => {
const w = HdWallet.fromMnemonic(mnemonic);
console.log('MetaMask sk:', w.metaMaskPrivateKey(0));
assert('6aad31c479c44230721b470570c12bd3f41e71b79d8f27ca08b913cbaeac25af'.toLowerCase() ===
w.metaMaskPrivateKey(0).toLowerCase());
});
})
See a complete project in the hdwallet branch of the field-support repo.
Make sure you have Node.js and NPM installed.
Open up a terminal and execute the following, assuming you hav
npx mnemonic-to-private-key "paste your 12 word phrase here".
Do NOT use online sites as you never know if they will store your phrase. In fact, even the above repository of "mnemonic-to-private-key" could be compromised, as the "Great Suspender" was. So it's best to use version pinning with npm.

RxJs emit after delay or next event on the stream

I've pairs of events: add1/add2/etc and remove1/remove2/etc. I'd like the following:
when an add1 is emitted on the stream
if DELAY transpires with no new add* emissions
emit remove1
if add* is emitted
emit remove1 for add1 immediately
emit remove* for add* after DELAY
This should continue for all emissions of add* on the stream.
Here's a test I've written using RxJS marble testing for this case:
import test from 'tape'
import { set, lensPath } from 'ramda'
import { TestScheduler } from 'rxjs/testing'
import hideAfterDelay from '../another/file'
import { actionCreators } from '../another/dir'
const prefix = 'epics -> notifications'
test(`${prefix} -> hideAfterDelay`, t => {
t.plan(1)
const scheduler = new TestScheduler(t.deepEqual)
const actionMap = {
a: createAddAction('hello!'),
b: createAddAction('goodbye!'),
x: actionCreators.notifications.remove('hello!'),
y: actionCreators.notifications.remove('goodbye!')
}
scheduler.run(({ cold, expectObservable }) => {
const actionStream = cold('a-------a-b-a------', actionMap)
const expected = '-----x-----x-y----x'
const actual = hideAfterDelay(5)(actionStream)
expectObservable(actual).toBe(expected, actionMap)
})
})
function createAddAction (name) {
const action = actionCreators.notifications.add(name)
const lens = lensPath(['payload', 'id'])
return set(lens, name, action)
}
I think the test is representative of the behavior I described above and that I want.
How can I write this observable? I've tried using timer and race but I haven't been able to get this working...
This is an epic using redux-observable, btw.
Using RxJS v6
Ok, I think I got a working solution using a closure and slightly modifying my test assertion.
First, the expected marble diagram should look like this
// input: a-------a-b-a------
// - expected: -----x-----x-y----x
// + expected: -----x----x-y----x
//
// Note above that the middle x and y emit at the same time as new
// `add*` actions on the source stream instead of one frame later
With that small change—which still feels consistent with my description in the question—I was able to get my test passing with the following:
import { of, timer, empty } from 'rxjs'
import { switchMap, mapTo, tap, merge } from 'rxjs/operators'
import { ofType } from '../operators'
import actionTypes from '../../actionTypes/notifications'
import { actionCreators } from '../..'
export default (delay = 3000) => actionStream => {
let immediateRemove
return actionStream.pipe(
ofType(actionTypes.ADD),
switchMap(action => {
let obs = empty()
if (immediateRemove) {
obs = of(immediateRemove)
}
const remove = actionCreators.notifications.remove(action.payload.id)
immediateRemove = remove
return obs.pipe(
merge(
timer(delay).pipe(
tap(() => {
immediateRemove = null
}),
mapTo(remove)
)
)
)
})
)
}
I've no idea if this is the best or right way to solve it, but I'm fairly certain it is a way.

Trying to import package d3/d3.js in Angular dart.

I have moved from Java to AngularDart for a project where I have to visualise some numbers and a threat level based on data.
I decided to try to do a pie/doughnut shape with pie slices showing data properties and the centre is to show the threat level as a coloured circle.
I found an old D3Dart package and used that for my first attempt. Works fine. I can build arc's including inner- and outer radius, start- and end-angle, etc.
Reading examples on how to build I was inspired to try and move to d3/d3.js, which has (I guess) a better interface to d3.js. I need to be able to better control how I display things f.ex. replace a node element in the DOM.
When tying to import the package with import 'package:d3/d3.js' as d3;
pub serve fails with the message:
> D:\apps\Dart\dart-sdk\bin\pub.bat serve web --port=54969 Loading
> source assets... Loading angular, test/pub_serve and
> dart_to_js_script_rewriter transformers... Serving SimplePie web on
> http://localhost:54969 [web] GET Served 2 assets. [web] GET styles.css
> => SimplePie|web/styles.css Build error: Transform BuilderTransformer: Instance of 'TemplatePlaceholderBuilder' on SimplePie|primary threw
> error: Error in <unknown source>: Illegal character '949'.
>
> Error in <unknown source>: Illegal character '949'.
Last line is repeated many times.
What am I missing in my import
pubspec.yaml:
name: SimplePie
description: A web app that uses AngularDart Components
version: 0.0.1
environment:
sdk: '>=1.24.0 <2.0.0'
dependencies:
color: any
angular: ^4.0.0
angular_components: ^0.8.0
d3: ^0.2.0
dev_dependencies:
angular_test: ^1.0.0
browser: ^0.10.0
dart_to_js_script_rewriter: ^1.0.1
test: ^0.12.0
transformers:
- angular:
entry_points:
- web/main.dart
- test/**_test.dart
- test/pub_serve:
$include: test/**_test.dart
- dart_to_js_script_rewriter
Snippet of my dart code that fails when I add d3/d3.js:
import 'dart:html';
import 'dart:math' as Math;
import 'package:d3/d3.js' as d3;
import 'package:angular_components/angular_components.dart';
import 'package:angular/angular.dart';
#Component (
selector: "pie-chart",
templateUrl: 'pie_chart.html',
directives: const[CORE_DIRECTIVES, materialDirectives],
providers: const[materialProviders]
)
class SimplePie implements AfterViewInit {
#ViewChild("containerPieChart")
List<num> pieSliceList;
num numberOfSlices;
Math.Random random = new Math.Random();
final num MAX_PIE_SLICE_SIZE = 20;
num totalPieSize;
num width;
num height;
num radius;
num strokeWidth;
var progressText;
void ngAfterViewInit() {
setup();
totalPieSize = 0;
for (num i = 0 ; i < random.nextInt(10) ; i++ ) {
var value = random.nextInt(MAX_PIE_SLICE_SIZE);
pieSliceList.add(value);
totalPieSize += value;
}
numberOfSlices = pieSliceList.length;
progressText = document.getElementById("progressText");
}
void setup () {
this.width = 800;
this.height = 800;
this.strokeWidth = 3;
this.radius = (Math.min(width, height) / 2) - 2 * strokeWidth;
}
}
I use IntelliJ IDE (latest) and Dart version 1.24.3.

Haxe Type Not Found

I'm trying to run the most basic Haxe program but keep getting errors.
The Main.hx file looks like this:
package;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.Lib;
import flixel.FlxGame;
import flixel.FlxState;
class Main extends Sprite {
var gameWidth:Int = 640; // Width of the game in pixels (might be less / more in actual pixels depending on your zoom).
var gameHeight:Int = 480; // Height of the game in pixels (might be less / more in actual pixels depending on your zoom).
var initialState:Class<FlxState> = MenuState; // The FlxState the game starts with.
var zoom:Float = -1; // If -1, zoom is automatically calculated to fit the window dimensions.
var framerate:Int = 60; // How many frames per second the game should run at.
var skipSplash:Bool = false; // Whether to skip the flixel splash screen that appears in release mode.
var startFullscreen:Bool = false; // Whether to start the game in fullscreen on desktop targets
// You can pretty much ignore everything from here on - your code should go in your states.
public static function main():Void
{
Lib.current.addChild(new Main());
}
public function new()
{
super();
if (stage != null)
{
init();
}
else
{
addEventListener(Event.ADDED_TO_STAGE, init);
}
}
private function init(?E:Event):Void
{
if (hasEventListener(Event.ADDED_TO_STAGE))
{
removeEventListener(Event.ADDED_TO_STAGE, init);
}
setupGame();
}
private function setupGame():Void
{
var stageWidth:Int = Lib.current.stage.stageWidth;
var stageHeight:Int = Lib.current.stage.stageHeight;
if (zoom == -1)
{
var ratioX:Float = stageWidth / gameWidth;
var ratioY:Float = stageHeight / gameHeight;
zoom = Math.min(ratioX, ratioY);
gameWidth = Math.ceil(stageWidth / zoom);
gameHeight = Math.ceil(stageHeight / zoom);
}
addChild(new FlxGame(gameWidth, gameHeight, initialState, zoom, framerate, framerate, skipSplash, startFullscreen));
}
}
Just the generic template file. When I run it in Terminal (running Mac OS X El Capitan), I get this error:
Main.hx:8: characters 7-21 : Type not found : flixel.FlxGame
Haven't had problems with the installations or anything and I am new to Haxe so I don't know where to start. Any ideas?
Thanks :)
Did you add the library when you try to run your game ?
You can do that by using the command line haxe -lib flixel -main Main ....
Or by writting an hxml file containing all your CLI arguments :
-lib flixel
-main Main
Update after #Gama11 comment :
HaxeFlixel used the OpenFL format for the compilation information (see http://www.openfl.org/documentation/projects/project-files/xml-format/).
So you should include include flixel library using : <haxelib name="flixel" />in your Project.xml file.

Watching TypeScript module vars in VS2013

In Visual Studio 2013 Update 2RC (TypeScript 1.0), although the following code works, if you set a breakpoint on age and hover over it, nothing appears. You have to watch Test.age.
But the code is correct, isn't it?
module Test
{
export var age: number;
export function go()
{
age = 40;
return age; // put a breakpoint here, and hover over age
}
}
Test.go();
Notice if you do not export age, the debugging works as expected!
The VS debugger and TypeScript source map emitter don't yet implement symbol mapping. To understand what's going on, look at the generated code:
var Test;
(function (Test) {
Test.age;
function go() {
Test.age = 40;
return Test.age;
}
Test.go = go;
})(Test || (Test = {}));
Test.go();
Note that there is no variable named age in scope at any point, only a property called age on the Test module.
Contrast this to the generated code to if you had removed export from age:
var Test;
(function (Test) {
var age;
function go() {
age = 40;
return age;
}
Test.go = go;
})(Test || (Test = {}));
Test.go();
Here, age does exist and the debugger can find it.

Resources